﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using Lamex.mNC.Common;
using System.Runtime.InteropServices;
using Lamex.NC.Model;
using DevExpress.XtraEditors.Popup;
using Lamex.Base;
using Lamex.NC.BLL;
using DevExpress.XtraSplashScreen;
using Lamex.Common;
using DevExpress.XtraBars.Design;
using Lamex.Interface;
using System.IO;
using Lamex.Library.UI;
using System.Threading;
using DevExpress.Utils.Svg;
using System.Xml;
using DevExpress.Utils.About;
using DevExpress.Utils.DPI;
using Lamex.Library.CommonClass;
using DevExpress.XtraGrid.Views.Grid;

namespace Lamex.mNC.UI
{
    public partial class frmNC_Convert_DKSJR_Processing : frmBaseChild
    {
        IntPtr handle;
        [DllImport("user32.dll", SetLastError = true)]

        private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        private const int GWL_STYLE = (-16);
        private const int WS_VISIBLE = 0x10000000;
        const Int32 WS_BORDER = (Int32)0x00800000L;
        const Int32 WS_THICKFRAME = (Int32)0x00040000L;
        const Int32 SWP_NOMOVE = 0x0002;
        const Int32 SWP_NOSIZE = 0x0001;
        const Int32 SWP_NOZORDER = 0x0004;
        const Int32 SWP_FRAMECHANGED = 0x0020;
        const Int32 SW_MAXIMIZE = 3;
        IntPtr HWND_NOTOPMOST = new IntPtr(-2);
        
        //[DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        //private static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);
        [DllImport("user32", EntryPoint = "SetWindowLong", SetLastError = true)]
        private static extern uint SetWindowLong(
        IntPtr hwnd,
        int nIndex,
        int dwNewLong
        );
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        static extern Int32 SetWindowPos(IntPtr hWnd,
   IntPtr hWndInsertAfter,
   Int32 X,
   Int32 Y,
   Int32 cx,
   Int32 cy,
   UInt32 uFlags
 );
        string PartNo = "";
        string TargetPath = "";
        bool isShow = true;
        string tipPath = "";
        string rountingType = "";
        string UpoldStr = "";
        string pathFileName = "";
        string DownOldStr = "";

        string LeftOldStr = "";

        string RightOldStr = "";
        string UpoldValue = "";

        string DownOldValue = "";

        string LeftOldValue = "";

        string RightOldValue = "";

        string cuttingType = "";
        string machineType = "";
        string nCSatuts = "";
        int widthNm1 = 0;
        int widthNm2 = 0;
        List<string> egdeList = new List<string>();
        string nC_DK_SJ01 = "";
        string nC_DK_SJ02 = "";
        public frmNC_Convert_DKSJR_Processing(string PartNo, string targetPath, string tipPath, string pathFileName)
        {
            //nC_DK_SJ01 = this.nC_DK_SJ01;
            egdeList.Clear();
            InitializeComponent();
            this.cmb_Up.TextChanged += new System.EventHandler(this.cmb_Up_TextChanged);
            this.cmb_Left.TextChanged += new System.EventHandler(this.cmb_Left_TextChanged);
            this.cmb_Down.TextChanged += new System.EventHandler(this.cmb_Down_TextChanged);
            this.cmb_Right.TextChanged += new System.EventHandler(this.cmb_Right_TextChanged);
            this.TargetPath = targetPath;
            Clipboard.SetText(TargetPath);
            if (handle == IntPtr.Zero)
                handle = FindWindow(null, "Creo Parametric");//Creo Parametric
           // InsertWindow insertwin = new InsertWindow(panel1, "", handle);
           
            //Update by Bill  2021.01.20
            SetParent(handle, this.panel1.Handle);
            // Win32API.SetWindowLong(new HandleRef(this.panel1, handle), Win32API.GWL_STYLE, Win32API.WS_VISIBLE);
            Win32API.SetWindowLong(panel1, handle, new HandleRef(this.panel1, handle), Win32API.GWL_STYLE, Win32API.WS_VISIBLE);
            Win32API.MoveWindow(handle, 0, 0, this.panel1.Width, this.panel1.Height, true);


            this.PartNo = PartNo;
            this.tipPath = tipPath;
            this.pathFileName = pathFileName;
            //this.TargetPath = "L:" + targetPath.Trim().ToLower().Replace(@"\\TX-FS10\tx-fs1\LAMEX".Trim().ToLower(), " ").Trim();

            this.Load += new EventHandler(frmNC_Convert_DKSJR_Processing_Load);

        }

        public void InitLoad(string PartNo, string targetPath, string tipPath, string pathFileName)
        {
            //nC_DK_SJ01 = this.nC_DK_SJ01;
            
            egdeList.Clear();
            //targetPath= "L:" + targetPath.Trim().ToLower().Replace(@"\\TX-FS10\tx-fs1\LAMEX".Trim().ToLower(), " ").Trim();
            this.TargetPath = targetPath;
            Clipboard.SetText(TargetPath);
            //radioGroup1.Enabled = false;
            chkPartConvert.Checked = false;
            this.PartNo = PartNo;
            this.tipPath = tipPath;
            this.pathFileName = pathFileName;
            ClearCutting();
            frmNC_Convert_DKSJR_Processing_Load(null, null);
            
            //ShowRountingTips();

            //Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\CreoFileOp.exe;L:\Share\MurphyMin\CreoBox\");


        }
        private void frmNC_Convert_DKSJR_Processing_Load(object sender, EventArgs e)
        {
            splitContainerControl1.Panel1.Width =(int)( 7.0/10.0 *double.Parse( splitContainerControl1.Width.ToString()));
            splitContainerControl1.Panel2.Width = (int)(3.0 / 10.0* double.Parse(splitContainerControl1.Width.ToString()));
            btnDrawLevel.Enabled = true;
            
            try
            {
                nCSatuts = "";
                NC_Convert_ProcessRecordInfo bll = BaseFactory<NC_Convert_ProcessRecord>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
                if (bll != null)
                {
                    
                    if (bll.NC_STATE.Trim()== "审核中")
                    {
                        
                        this.Text = "NC审核_桌子SJR";
                        nCSatuts = "审核中";
                        txtPart_No.Text = PartNo;
                        cmbWidth1.Visible = false;
                        cmbWidth2.Visible = false;
                        cmbThickness.Visible = false;
                        cmb_Up.ReadOnly = true;
                        cmb_Down.ReadOnly = true;
                        cmb_Left.ReadOnly = true;
                        cmb_Right.ReadOnly = true;
                        cmb_UpValue.ReadOnly = true;
                        cmb_DownValue.ReadOnly = true;
                        cmb_LeftValue.ReadOnly = true;
                        cmb_RightValue.ReadOnly = true;
                        plLeft.Visible = false;
                        plRight.Visible = true;
                        FileInfo fi = new FileInfo(tipPath);
                        string path = fi.DirectoryName;
                        string movePath = fi.DirectoryName;
                        string name = fi.Name;
                        path = path + @"\" + pathFileName + ".csv";

                        DataTable dtCsv = new DataTable();
                        //if (true) return;
                        Lamex.Common.ExecelHelper.csv2dt(path, 0, dtCsv);
                        //开始填充数据
                        cboxGrain_Direct.Text = dtCsv.Rows[0]["木纹方向"].ToString();
                        chkPartConvert.Checked = dtCsv.Rows[0]["旋转标识"].ToString() == "0" ? false : true;
                        txt_Width1.Text = dtCsv.Rows[0]["阔度_1"].ToString();
                        txt_Width2.Text = dtCsv.Rows[0]["阔度_2"].ToString();
                        cboxPart_Thick.Text = dtCsv.Rows[0]["厚度"].ToString();

                        cmb_Up.Text = dtCsv.Rows[0]["封边_C2"].ToString();
                        cmb_Down.Text = dtCsv.Rows[0]["封边_C1"].ToString();
                        cmb_Left.Text = dtCsv.Rows[0]["封边_C3"].ToString();
                        cmb_Right.Text = dtCsv.Rows[0]["封边_C4"].ToString();
                        if (dtCsv.Rows[0]["C_封边_S2"].ToString().Substring(0,1).ToLower()=="s")
                            cmb_UpValue.Text = "S" + dtCsv.Rows[0]["封边_T2"].ToString();
                        else
                            cmb_UpValue.Text = dtCsv.Rows[0]["封边_T2"].ToString();
                        if (dtCsv.Rows[0]["C_封边_S1"].ToString().Substring(0, 1).ToLower() == "s")
                            cmb_DownValue.Text ="S"+ dtCsv.Rows[0]["封边_T1"].ToString();
                        else
                            cmb_DownValue.Text = dtCsv.Rows[0]["封边_T1"].ToString();
                        if (dtCsv.Rows[0]["C_封边_S3"].ToString().Substring(0, 1).ToLower() == "s")
                            cmb_LeftValue.Text = "S" + dtCsv.Rows[0]["封边_T3"].ToString();
                        else
                            cmb_LeftValue.Text = dtCsv.Rows[0]["封边_T3"].ToString();
                        if (dtCsv.Rows[0]["C_封边_S4"].ToString().Substring(0, 1).ToLower() == "s")
                            cmb_RightValue.Text = "S" + dtCsv.Rows[0]["封边_T4"].ToString();
                        else
                            cmb_RightValue.Text = dtCsv.Rows[0]["封边_T4"].ToString();

                        CuttingWay();
                        //loading all select values
                        //loadMaterialInfo();

                        //load tip image into form
                        List<string> lst = new List<string>();
                        lst.Add(tipPath);
                        ucShowPic1.LoadImageList(lst);

                        if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                        {
                            btnImport.Enabled = true;
                            simpleButton1.Enabled = true;
                            btnAutoCheck.Enabled = true;
                            btnDrawLevel.Enabled = true;
                            Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\CreoFileOp.exe;L:\Share\MurphyMin\CreoBox\");

                        }
                        else
                        {
                            btnImport.Enabled = false;
                            simpleButton1.Enabled = false;
                            btnAutoCheck.Enabled = false;
                            btnDrawLevel.Enabled = false;
                        }
                    }
                    else
                    {
                        this.Text = "NC转码_桌子SJR";
                        cmbWidth1.Visible = true;
                        cmbWidth2.Visible = true;
                        cmbThickness.Visible = true;
                        cmb_Up.ReadOnly = false;
                        cmb_Down.ReadOnly = false;
                        cmb_Left.ReadOnly = false;
                        cmb_Right.ReadOnly = false;
                        cmb_UpValue.ReadOnly = false;
                        cmb_DownValue.ReadOnly = false;
                        cmb_LeftValue.ReadOnly = false;
                        cmb_RightValue.ReadOnly = false;
                        plLeft.Visible = true;
                        plRight.Visible = false;

                        egdeList.Clear();
                        txt_Width2.Text = "";
                        txt_Width1.Text = "";
                        cboxPart_Thick.Text = "";
                        cmbWidth1.Text = "";
                        cmbWidth2.Text = "";
                        cmbThickness.Text = "";
                        chkPartConvert.Checked = false;
                        //set data element to UI from NC_Convert_TaskList fields value and set rounting 
                        NC_Convert_TaskListInfo model = BaseFactory<NC_Convert_TaskList>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
                        if (model != null)
                        {

                            txtPart_No.Text = PartNo;
                            if(model.GRAIN!=null)
                            {
                                if (model.GRAIN.ToLower().Contains("h"))
                                    cboxGrain_Direct.Text = "H_横纹";
                                else if (model.GRAIN.ToLower().Contains("v"))
                                    cboxGrain_Direct.Text = "V_直纹";
                            }
                            else
                                cboxGrain_Direct.Text = "N_无纹";
                            //cboxGrain_Direct.Text = model.GRAIN;
                            //2020-11-10 by jackey
                            //if (model.THICK != null)
                            //    cboxPart_Thick.Text = model.THICK.ToString();
                            //if (model.FINISH_WIDTH != null)
                            //    txt_Width1.Text = model.FINISH_WIDTH.ToString();
                            //if (model.FINISH_DEPTH != null)
                            //    txt_Width2.Text = model.FINISH_DEPTH.ToString();
                            //set cuttingway value
                            CuttingWay();
                            //loading all select values
                            loadMaterialInfo();

                            //load tip image into form
                            List<string> lst = new List<string>();
                            lst.Add(tipPath);
                            ucShowPic1.LoadImageList(lst);

                            if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                            {
                                btnImport.Enabled = true;
                                simpleButton1.Enabled = true;
                                btnAutoCheck.Enabled = true;
                                Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\CreoFileOp.exe;L:\Share\MurphyMin\CreoBox\");

                            }
                            else
                            {
                                btnImport.Enabled = false;
                                simpleButton1.Enabled = false;
                                btnAutoCheck.Enabled = false;
                            }
                            //ucControls.ucShowPic uc = new ucControls.ucShowPic();
                            //uc.LoadImageList(lst);
                            //uc.Dock = DockStyle.Fill;
                            //uc.DoubleClick += new EventHandler(uc_DoubleClick);
                            //splitContainerControl1.Panel2.Controls.Add(uc);
                            //Image img = Image.FromFile(tipPath);
                            //Image bmp = new Bitmap(img);
                            //img.Dispose();
                            //pictureEdit2.Image = bmp;
                            //
                        }

                        if ((!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                            btnDrawLevel.Enabled = false;
                        else
                            btnDrawLevel.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
        }
        private void uc_DoubleClick(object sender, EventArgs e)
        {
            pictureEdit2_DoubleClick(null, null);
            //DataTable dt = Lamex.Base.BaseBuildSql.GetDataTableBySql("");
        }
    /// <summary>
    /// 工艺路线提示ReturnCuttingType
    /// </summary>
    private void ShowRountingTips()
        {
            
            //DataTable dt = Lamex.Base.BaseBuildSql.GetDataTableBySql("");
        }

        //public byte[] GetByteImage(Image img)
        //{
        //    byte[] bt = null;
        //    if (!img.Equals(null))
        //    {
        //        using (MemoryStream mostream = new MemoryStream())
        //        {
        //            Bitmap bmp = new Bitmap(img);
        //            bmp.Save(mostream, System.Drawing.Imaging.ImageFormat.Bmp);//将图像以指定的格式存入缓存内存流

        //            bt = new byte[mostream.Length];
        //            mostream.Position = 0;//设置留的初始位置
        //            mostream.Read(bt, 0, Convert.ToInt32(bt.Length));
        //        }
        //    }
        //    return bt;
        //}
        /// <summary>
        /// select cuttingway type
        /// </summary>
        private void CuttingWay()
        {
            //PartNo = "9033233080";
            NC_Convert_TaskListInfo model = BaseFactory<NC_Convert_TaskList>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
            StringBuilder str = new StringBuilder();
            str.Append("物料号码:"+PartNo + "\r\n");
            DataTable dt = BaseBuildSql.GetDataTableBySql(@" select b.* from IE_Part_Routing a 
                                                             join IE_Routing_Combination b on a.GROUP_CODE = b.GROUP_CODE
                                                             where a.PART_NO = '"+PartNo+"'");
            if(dt.Rows.Count!=0)
            {
                string rounting = dt.Rows[0]["ROUTING_CODE"].ToString();
                rountingType = rounting;
                if (!string.IsNullOrEmpty(rounting))
                {
                    cuttingType = ReturnCuttingType.GetCuttingType(rounting);
                    if ("COMBIMA" == cuttingType)
                    {
                        str.Append("开料方式：" + "COMBIMA" + "\r\n");
                        //radioGroup1.SelectedIndex = 0;
                        

                    }
                    else if ("BIMA" == cuttingType)
                    {
                        str.Append("开料方式：" + "BIMA" + "\r\n");
                        //radioGroup1.SelectedIndex = 1;
                    }
                    else if ("小板线" == cuttingType)
                    {
                        str.Append("开料方式：" + "小板线" + "\r\n");
                        //radioGroup1.SelectedIndex = 2;

                        
                    }
                    else if ("斜边线" == cuttingType)
                    {
                        str.Append("开料方式：" + "斜边线" + "\r\n");
                        //radioGroup1.SelectedIndex = 2;

                        
                        //radioGroup1.SelectedIndex = 3;
                    }
                    if ((!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                    {
                        if (model.THICK != null)
                            cboxPart_Thick.Text = model.THICK.ToString();
                        if (model.FINISH_WIDTH != null)
                            txt_Width1.Text = model.FINISH_WIDTH.ToString();
                        if (model.FINISH_DEPTH != null)
                            txt_Width2.Text = model.FINISH_DEPTH.ToString();
                        cboxPart_Thick.ReadOnly = false;
                        txt_Width1.ReadOnly = false;
                        txt_Width2.ReadOnly = false;
                    }
                   //机械加工：
                    machineType = ReturnCuttingType.GetMachineType(rounting);
                    
                    str.Append("加工机械：" + machineType + "\r\n");
                    str.Append("工艺路线：" + dt.Rows[0]["ROUTING_DESC"].ToString() + "\r\n");
                    memoEdit1.Text = str.ToString();



                    

                }
                
            }
            //radioGroup1.Properties.Items[3].Enabled = true;


           
        }
        /// <summary>
        /// load MaterialInfo to rubber edge config color
        /// </summary>
        private void loadMaterialInfo()
        {
            cmb_Up.Properties.Items.Clear();
            cmb_Down.Properties.Items.Clear();
            cmb_Left.Properties.Items.Clear();
            cmb_Right.Properties.Items.Clear();
            DataTable dt = BaseBuildSql.GetDataTableBySql("select EDGE_CODE from [dbo].[NC_Convert_Edge_Material_Info] order by CTRL_SEQUENCE ");
            if(dt.Rows.Count!=0)
            {
                foreach(DataRow dr in dt.Rows)
                {
                    cmb_Up.Properties.Items.Add(dr["EDGE_CODE"].ToString());
                    cmb_Down.Properties.Items.Add(dr["EDGE_CODE"].ToString());
                    cmb_Left.Properties.Items.Add(dr["EDGE_CODE"].ToString());
                    cmb_Right.Properties.Items.Add(dr["EDGE_CODE"].ToString());
                }
            }
        }
        
        private void frmNC_Converting_Processing_DKSJR_Resize(object sender, EventArgs e)
        {
            splitContainerControl1.SplitterPosition = this.Width / 2;
        }

        /// <summary>
        /// if chkpartconvert is true , wrap width1 and width2 values
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkPartConvert_CheckedChanged(object sender, EventArgs e)
        {
            if (nCSatuts == "审核中") return;
            string tempValue = "";
            if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
            {

                if (cboxGrain_Direct.Text.ToLower().Contains("h"))
                    cboxGrain_Direct.Text = "V_直纹";
                else if (cboxGrain_Direct.Text.ToLower().Contains("v"))
                    cboxGrain_Direct.Text = "H_横纹";
                else
                    cboxGrain_Direct.Text = "N_无纹";
            }
            else
            {
                tempValue = txt_Width2.Text;
                txt_Width2.Text = txt_Width1.Text;
                txt_Width1.Text = tempValue;
                //NC_Convert_TaskListInfo model = BaseFactory<NC_Convert_TaskList>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
                //if (model != null)
                //{
                if (cboxGrain_Direct.Text.ToLower().Contains("h"))
                    cboxGrain_Direct.Text = "V_直纹";
                else if (cboxGrain_Direct.Text.ToLower().Contains("v"))
                    cboxGrain_Direct.Text = "H_横纹";
                else
                    cboxGrain_Direct.Text = "N_无纹";
                //}
            }

        }
        /// <summary>
        /// select index decision detp value
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void btnImport_Click(object sender, EventArgs e)
        {
            egdeList.Clear();
            //FileStream fs = null;
            //StreamWriter sw = null;
            
            try
            {
                

                if (false == AlertMsg()) return;
                if(string.IsNullOrEmpty(rountingType))
                {
                    XtraMessageBox.Show("工艺路线不能为空!");
                    return;
                }
                
                if (string.IsNullOrEmpty(cmb_Up.Text))
                {
                    XtraMessageBox.Show("胶边上不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(cmb_Down.Text))
                {
                    XtraMessageBox.Show("胶边下不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(cmb_Left.Text))
                {
                    XtraMessageBox.Show("胶边左不能为空!");
                    return;
                }
                
                if (string.IsNullOrEmpty(cmb_Right.Text))
                {
                    XtraMessageBox.Show("胶边右不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(cmb_UpValue.Text))
                {
                    XtraMessageBox.Show("胶边上值不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(cmb_DownValue.Text))
                {
                    XtraMessageBox.Show("胶边下值不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(cmb_LeftValue.Text))
                {
                    XtraMessageBox.Show("胶边左值不能为空!");
                    return;
                }

                if (string.IsNullOrEmpty(cmb_RightValue.Text))
                {
                    XtraMessageBox.Show("胶边右值不能为空!");
                    return;
                }
                //
                if (!(cmb_Up.Text== "PVC_NIL_不适用"|| cmb_Up.Text == "PVC_XXX_不封"))
                {
                    if(cmb_UpValue.Text=="0")
                    {
                        XtraMessageBox.Show("胶边上不能为0!");
                        return;
                    }
                }
                if (!(cmb_Down.Text == "PVC_NIL_不适用" || cmb_Down.Text == "PVC_XXX_不封"))
                {
                    if (cmb_DownValue.Text == "0")
                    {
                        XtraMessageBox.Show("胶边下不能为0!");
                        return;
                    }
                }
                if (!(cmb_Left.Text == "PVC_NIL_不适用" || cmb_Left.Text == "PVC_XXX_不封"))
                {
                    if (cmb_LeftValue.Text == "0")
                    {
                        XtraMessageBox.Show("胶边左不能为0!");

                        return;
                    }
                }
                if (!(cmb_Right.Text == "PVC_NIL_不适用" || cmb_Right.Text == "PVC_XXX_不封"))
                {
                    if (cmb_RightValue.Text == "0")
                    {
                        XtraMessageBox.Show("胶边右不能为0!");
                        return;
                    }
                }
                DataTable dtUp = Lamex.Base.BaseBuildSql.GetDataTableBySql("select EDGE_CODE from [dbo].[NC_Convert_Edge_Material_Info]  where EDGE_CODE='"+cmb_Up.Text+"'");
                if(dtUp.Rows.Count==0)
                {
                    XtraMessageBox.Show("胶边右不存在!");
                    return;
                }
                DataTable dtDown = Lamex.Base.BaseBuildSql.GetDataTableBySql("select EDGE_CODE from [dbo].[NC_Convert_Edge_Material_Info]  where EDGE_CODE='" + cmb_Down.Text + "'");
                if (dtDown.Rows.Count == 0)
                {
                    XtraMessageBox.Show("胶边下不存在!");
                    return;
                }
                DataTable dtLeft = Lamex.Base.BaseBuildSql.GetDataTableBySql("select EDGE_CODE from [dbo].[NC_Convert_Edge_Material_Info]  where EDGE_CODE='" + cmb_Left.Text + "'");
                if (dtLeft.Rows.Count == 0)
                {
                    XtraMessageBox.Show("胶边左不存在!");
                    return;
                }
                DataTable dtRight= Lamex.Base.BaseBuildSql.GetDataTableBySql("select EDGE_CODE from [dbo].[NC_Convert_Edge_Material_Info]  where EDGE_CODE='" + cmb_Right.Text + "'");
                if (dtRight.Rows.Count == 0)
                {
                    XtraMessageBox.Show("胶边右不存在!");
                    return;
                }
                if (string.IsNullOrEmpty(cmbWidth1.Text)) cmbWidth1.Text = "0";
                if (string.IsNullOrEmpty(cmbWidth2.Text)) cmbWidth2.Text = "0";
                if (string.IsNullOrEmpty(cmbThickness.Text)) cmbThickness.Text = "0";
                
                if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                    //if (1 != 1)
                {
                    StringBuilder fileContent = new StringBuilder();
                    Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\NcDims.exe;L:\Share\MurphyMin\CreoBox\");
                    //XtraMessageBox.Show("NcDims.exe 成功调用");
                    while (true)
                    {
                        DataTable dtDim = Lamex.Base.BaseBuildSql.GetDataTableBySql(" select * from NC_Convert_TaskList where  PART_NO='" + txtPart_No.Text + "'");
                        if (dtDim.Rows.Count != 0)
                        {

                            cboxPart_Thick.Text = dtDim.Rows[0]["NC_THICK"].ToString();
                            txt_Width1.Text = dtDim.Rows[0]["NC_FINISH_WIDTH"].ToString();
                            txt_Width2.Text = dtDim.Rows[0]["NC_FINISH_DEPTH"].ToString();
                            //if (string.IsNullOrEmpty(txt_Width1.Text)) widthNm1 = 0;
                            //else
                            //    widthNm1 = int.Parse(txt_Width1.Text);
                            //if (string.IsNullOrEmpty(txt_Width2.Text)) widthNm2 = 0;
                            //else
                            //    widthNm2 = int.Parse(txt_Width2.Text);
                            if (!string.IsNullOrEmpty(txt_Width1.Text) && !string.IsNullOrEmpty(txt_Width2.Text) && !string.IsNullOrEmpty(cboxPart_Thick.Text))
                            {
                                //XtraMessageBox.Show(" 不为空");
                                break;
                            }
                            else
                            {
                                //XtraMessageBox.Show(" 为空");
                                continue;
                            }
                        }

                    }

                    if (!(cmb_UpValue.Text.ToLower().Contains("s") || cmb_DownValue.Text.ToLower().Contains("s") || cmb_LeftValue.Text.ToLower().Contains("s") || cmb_RightValue.Text.ToLower().Contains("s")))
                    {
                        


                        fileContent.Append("阔度_1=" + txt_Width1.Text +"+"+ cmbWidth1.Text+ "\r\n");
                        fileContent.Append("阔度_2=" + txt_Width2.Text + "+" + cmbWidth2.Text + "\r\n");
                        fileContent.Append("开料方式=" + "\"" + cuttingType + "\"" + "\r\n");
                        fileContent.Append("生效日期=" + "\"" + DateTime.Now.ToString("yyyy-MM-dd") + "\"" + "\r\n");
                        fileContent.Append("制图=" + "\"" + Loginer.CurrentUser.AccountName + "\"" + "\r\n");
                        fileContent.Append("审核=" + "\"" + Loginer.CurrentUser.AccountName + "\"" + "\r\n");
                        fileContent.Append("部件编号=" + "\"" + PartNo + "\"" + "\r\n");
                        fileContent.Append("木纹方向=" + "\"" + cboxGrain_Direct.Text + "\"" + "\r\n");
                        fileContent.Append("厚度=" + cboxPart_Thick.Text + "\r\n");
                        fileContent.Append("封边_t1=" + cmb_DownValue.Text + "\r\n");
                        fileContent.Append("封边_t2=" + cmb_UpValue.Text   + "\r\n");
                        fileContent.Append("封边_t3=" + cmb_LeftValue.Text + "\r\n");
                        fileContent.Append("封边_t4=" + cmb_RightValue.Text + "\r\n");
                        fileContent.Append("封边_c1=" + "\"" + cmb_Down.Text + "\"" + "\r\n");
                        fileContent.Append("封边_c2=" + "\"" + cmb_Up.Text + "\"" + "\r\n");
                        fileContent.Append("封边_c3=" + "\"" + cmb_Left.Text + "\"" + "\r\n");
                        fileContent.Append("封边_c4=" + "\"" + cmb_Right.Text + "\"" + "\r\n");
                    }
                    else
                    {
                        fileContent.Append("阔度_1=" + txt_Width1.Text + "+" + cmbWidth1.Text + "\r\n");
                        fileContent.Append("阔度_2=" + txt_Width2.Text + "+" + cmbWidth2.Text + "\r\n");
                        fileContent.Append("开料方式=" + "\"" + cuttingType + "\"" + "\r\n");
                        fileContent.Append("生效日期=" + "\"" + DateTime.Now.ToString("yyyy-MM-dd") + "\"" + "\r\n");
                        fileContent.Append("制图=" + "\"" + Loginer.CurrentUser.AccountName + "\"" + "\r\n");
                        fileContent.Append("审核=" + "\"" + Loginer.CurrentUser.AccountName + "\"" + "\r\n");
                        fileContent.Append("部件编号=" + "\"" + PartNo + "\"" + "\r\n");
                        fileContent.Append("木纹方向=" + "\"" + cboxGrain_Direct.Text + "\"" + "\r\n");
                        fileContent.Append("厚度=" + cboxPart_Thick.Text + "\r\n");
                        fileContent.Append("封边_t1=" + cmb_DownValue.Text.Replace("S","").Trim() + "\r\n");
                        fileContent.Append("封边_t2=" + cmb_UpValue.Text.Replace("S", "").Trim() + "\r\n");
                        fileContent.Append("封边_t3=" + cmb_LeftValue.Text.Replace("S", "").Trim() + "\r\n");
                        fileContent.Append("封边_t4=" + cmb_RightValue.Text.Replace("S", "").Trim() + "\r\n");
                        fileContent.Append("封边_c1=" + "\"" + cmb_Down.Text + "\"" + "\r\n");
                        fileContent.Append("封边_c2=" + "\"" + cmb_Up.Text + "\"" + "\r\n");
                        fileContent.Append("封边_c3=" + "\"" + cmb_Left.Text + "\"" + "\r\n");
                        fileContent.Append("封边_c4=" + "\"" + cmb_Right.Text + "\"" + "\r\n");
                        if (cmb_DownValue .Text.ToLower().Contains("s"))
                            fileContent.Append("斜边_1=" + "\"" + "S" + "\"" + "\r\n");
                        else
                            fileContent.Append("斜边_1=" + "\"" + " " + "\"" + "\r\n");
                        if (cmb_UpValue.Text.ToLower().Contains("s"))
                            fileContent.Append("斜边_2=" + "\"" + "S" + "\"" + "\r\n");
                        else
                            fileContent.Append("斜边_2=" + "\"" + " " + "\"" + "\r\n");
                        if (cmb_LeftValue.Text.ToLower().Contains("s"))
                            fileContent.Append("斜边_3=" + "\"" + "S" + "\"" + "\r\n");
                        else
                            fileContent.Append("斜边_3=" + "\"" + " " + "\"" + "\r\n");
                        if (cmb_RightValue.Text.ToLower().Contains("s"))
                            fileContent.Append("斜边_4=" + "\"" + "S" + "\"" + "\r\n");
                        else
                            fileContent.Append("斜边_4=" + "\"" + " " + "\"" + "\r\n");
                    }
                    string path1 = fileContent.ToString();
                    Clipboard.SetDataObject(fileContent.ToString());
                    Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\CreoRelation.exe;L:\Share\MurphyMin\CreoBox\");
                    
                    //XtraMessageBox.Show("关系导入成功！");
                }
                else

                {
                   
                   
                }

                //open NC exe
                


            }
            catch(Exception ex)
            {
                
                XtraMessageBox.Show(ex.Message);
            }
        }
        private double ReValue(double fristValue, double SecondValue)
        {
            double dValue = fristValue + SecondValue;
            if (dValue == 1.2)
                dValue = 1.5;
            if (dValue == 0.6)
                dValue = 0.5;
            if (dValue == 2)
                dValue = 2;
            if (dValue == 2.6)
                dValue = 2.5;
            if (dValue == 4)
                dValue = 4;
            if (dValue == 0)
                dValue = 0;
            return dValue;

        }
        /// <summary>
        /// 判断是否为数字
        /// </summary>
        /// <param name="message"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        protected bool isNumberic(string message)
        {
         
            System.Text.RegularExpressions.Regex rex =
            new System.Text.RegularExpressions.Regex(@"^\d+$");
        
            if (rex.IsMatch(message))
            {
                return true;
            }
            else
                return false;
        }
        /// <summary>
        /// 提示
        /// </summary>
        private bool AlertMsg()
        {
            if (cmb_Up.Text == "")
            {
                XtraMessageBox.Show("胶边代码不能为空！");
                return false;
            }
            if (cmb_Down.Text == "")
            {
                XtraMessageBox.Show("胶边代码不能为空！");
                return false;
            }
            if (cmb_Left.Text == "")
            {
                XtraMessageBox.Show("胶边代码不能为空！");
                return false;
            }
            if (cmb_Right.Text == "")
            {
                XtraMessageBox.Show("胶边代码不能为空！");
                return false;
            }
            if (cmb_UpValue.Text == "")
            {
                XtraMessageBox.Show("胶边值不能为空！");
                return false;
            }
            if (cmb_DownValue.Text == "")
            {
                XtraMessageBox.Show("胶边值不能为空！");
                return false;
            }
            if (cmb_LeftValue.Text == "")
            {
                XtraMessageBox.Show("胶边值不能为空！");
                return false;
            }
            if (cmb_RightValue.Text == "")
            {
                XtraMessageBox.Show("胶边值不能为空！");
                return false;
            }
            return true;
        }
        private void ClearCutting()
        {
            cmb_Up.Text = "";
            cmb_Down.Text = "";
            cmb_Left.Text = "";
            cmb_Right.Text = "";
            cmb_UpValue.Text = "";
            cmb_DownValue.Text = "";
            cmb_LeftValue.Text = "";
            cmb_RightValue.Text = "";
        }
        private void btnNCImport_Click(object sender, EventArgs e)
        {
            try
            {
                
                string sourcePath = @"C:\Imawop\Src2\";
                string fmlPath = @"M:\MES\FML\";
                string fmcPath = @"M:\MES\FMC\";
                string dxfPath = @"Z:\D2f_SJR\2_已整理\DXF_612\";
                string cNcPath = @"Z:\D2f_SJR\2_已整理\DXF_3013\";
                //string nC_DK_SJ01 = "";
                //string nC_DK_SJ02 = "";
                NC_Convert_ProcessRecordInfo bll = BaseFactory<NC_Convert_ProcessRecord>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
                if (bll != null)
                {

                    bll.CONVERTED_TIME = DateTime.Now;
                    bll.CONVERTED_ENGINEER = Loginer.CurrentUser.AccountName;
                    bll.LOCKED_TIME = null;
                    bll.LOCKED_USER = null;
                    
                    if (bll.NC_STATE.Trim() == "已转码")
                    {
                        XtraMessageBox.Show("已确认，请勿重复确认！");
                        return;
                    }
                    else if (bll.NC_STATE.Trim() == "转码中")
                        bll.NC_STATE = "已转码".Trim();
                    else if (bll.NC_STATE.Trim() == "审核中")
                    {
                        XtraMessageBox.Show("审核中！");
                        return;
                    }
                    else if (bll.NC_STATE.Trim() == "已审核")
                    {
                        XtraMessageBox.Show("已审核！");
                        return;
                    }
                    else if (bll.NC_STATE.Trim() == "待修改")
                    {
                        XtraMessageBox.Show("此单有修改，请重新进入！");
                        return;
                    }
                    else if (bll.NC_STATE.Trim() == "改图纸")
                    {
                        XtraMessageBox.Show("此单有修改，请重新进入！");
                        return;

                    }

                egdeList.Clear();
                FileInfo fi = new FileInfo(tipPath);
                string path = fi.DirectoryName;
                string movePath = fi.DirectoryName;
                string name = fi.Name;
                path = path + @"\" + pathFileName + ".csv";

                if (!File.Exists(path))
                {
                    XtraMessageBox.Show(path + "路径不存在！");
                    return;
                }
                
               
                XmlDocument doc = new XmlDocument();
                doc.Load(Application.StartupPath + "\\PicturePathConfig.xml");
                XmlNode xn = doc.SelectSingleNode("Pictures");
                XmlNodeList xnl = xn.ChildNodes;
                foreach (XmlNode xn1 in xnl)
                {
                    XmlElement xe = (XmlElement)xn1;
                    XmlNodeList xn2 = xe.ChildNodes;
                    foreach (XmlElement x2 in xn2)
                    {
                        if (x2.Name == "NcfmlPath")
                            fmlPath = x2.InnerText;
                        if (x2.Name == "NcfmcPath")
                            fmcPath = x2.InnerText;
                        if (x2.Name == "NcdxfPath")
                            dxfPath = x2.InnerText;
                        if (x2.Name == "NccNcPath")
                            cNcPath = x2.InnerText;
                        if (x2.Name == "NC_DK_SJ01")
                                nC_DK_SJ01 = x2.InnerText;
                        if (x2.Name == "NC_DK_SJ02")
                                nC_DK_SJ02 = x2.InnerText;
                        }
                }

                   
                    DataTable dtTask = BaseBuildSql.GetDataTableBySql(" select *from NC_Convert_TaskList where PART_NO='" + PartNo + "'");

                string filePath = sourcePath + txtPart_No.Text + "_SNG.FML";//c盘
                string fileFml = TargetPath + txtPart_No.Text + "_SNG.FML";//创建目标盘FML
                string fileFmlPath = fmlPath + txtPart_No.Text + "_SNG.FML";
                string fileSngMfc = TargetPath + txtPart_No.Text + "_SNG.FMC";//创建目标盘MFC单开
                string fileDBLMfc = TargetPath + txtPart_No.Text + "_DBL.FMC";//创建目标盘MFC双开
                string fileSrcSngFmc = fmcPath + txtPart_No.Text + "_SNG.FMC";
                string fileSrcDblFmc = fmcPath + txtPart_No.Text + "_DBL.FMC";
                string fileXSngDxf = TargetPath + txtPart_No.Text + "_SNG.DXF";//创建目标盘DXF单开
                string fileXDBLDxf = TargetPath + txtPart_No.Text + "_DBL.DXF";//创建目标盘DXF单开  

                string fileSngDxf = dxfPath + txtPart_No.Text + "_SNG.DXF";
                string fileDblDxf = dxfPath + txtPart_No.Text + "_DBL.DXF";

                string fileCncSngDxf = cNcPath + txtPart_No.Text + "_SNG.DXF";
                string fileCncDblDxf = cNcPath + txtPart_No.Text + "_DBL.DXF";


                string singleTp1Asm = "tpl_prt_ref.asm";
                string singleTp1Drw = "tpl_prt_ref.drw";
                string doubleTp1Asm = "tpl_prt_ref_asm.asm";
                string doubleTp1Drw = "tpl_prt_ref_asm.drw";

                string singleTp1AsmPath = TargetPath + @"\" + singleTp1Asm;
                string singleTp1DrwPath = TargetPath + @"\" + singleTp1Drw;
                string doubleTp1AsmPath = TargetPath + @"\" + doubleTp1Asm;
                string doubleTp1DrwPath = TargetPath + @"\" + doubleTp1Drw;
                DataTable dtCsv = new DataTable();
                //if (true) return;
                Lamex.Common.ExecelHelper.csv2dt(path, 0, dtCsv);
                    if (string.IsNullOrEmpty(PartNo))
                {
                    XtraMessageBox.Show("部件号不能不空！");
                    return;
                }
                if (!Directory.Exists(TargetPath))
                {
                    XtraMessageBox.Show("目标路径不存在！");
                    return;
                }
                if (!Directory.Exists(sourcePath))
                {
                    XtraMessageBox.Show(@"C:\Imawop\Src2路径不存在");
                    return;
                }


                #region""
                //if (machineType.ToLower() == "puh")
                //{
                //    if (Directory.Exists(filePath))
                //    {
                //        XtraMessageBox.Show("FML程序不存在！");
                //        return;
                //    }
                //    if (File.Exists(fileFml))//删除原有FML
                //        File.Delete(fileFml);
                //    File.Move(filePath, fileFml);//c-target

                //    FileInfo singledrw = new FileInfo(singleTp1DrwPath);//时间对比
                //    FileInfo singleDxf = new FileInfo(fileXSngDxf);
                //    FileInfo singlefml = new FileInfo(fileFml);
                //    FileInfo singleMfc = new FileInfo(fileSngMfc);
                //    FileInfo sinleAsm = new FileInfo(singleTp1AsmPath);
                //    FileInfo csvFile = new FileInfo(path);

                //    FileInfo dblMfc = new FileInfo(fileDBLMfc);
                //    FileInfo dblDxf = new FileInfo(fileXDBLDxf);
                //    if (sinleAsm.LastWriteTime > csvFile.LastWriteTime)
                //    {
                //        XtraMessageBox.Show(sinleAsm.FullName + "文件生成时间大于" + csvFile.FullName);
                //        return;
                //    }
                //    if (singleDxf.LastWriteTime > singlefml.LastWriteTime)
                //    {
                //        XtraMessageBox.Show(singleDxf.FullName + "文件生成时间大于" + singlefml.FullName);
                //        return;
                //    }


                //    if (File.Exists(fileSngMfc))
                //        File.Delete(fileSngMfc);


                //}
                //else if (machineType.ToLower() == "bima")
                //{

                //    //删除
                //    if (!File.Exists(fileSngMfc))
                //    {
                //        XtraMessageBox.Show(fileSngMfc + "程序不存在！");
                //        return;
                //    }
                //    if (File.Exists(fileDBLMfc))
                //    {
                //        XtraMessageBox.Show(fileDBLMfc + "程序不存在！");
                //        return;

                //    }
                //    FileInfo singledrw = new FileInfo(singleTp1DrwPath);//时间对比
                //    FileInfo dbldrw = new FileInfo(doubleTp1DrwPath);
                //    FileInfo singleDxf = new FileInfo(fileXSngDxf);
                //    FileInfo singlefml = new FileInfo(fileFml);
                //    FileInfo singleMfc = new FileInfo(fileSngMfc);
                //    FileInfo sinleAsm = new FileInfo(singleTp1AsmPath);
                //    FileInfo dblAsm = new FileInfo(doubleTp1AsmPath);
                //    FileInfo csvFile = new FileInfo(path);

                //    FileInfo dblMfc = new FileInfo(fileDBLMfc);
                //    FileInfo dblDxf = new FileInfo(fileXDBLDxf);
                //    if (sinleAsm.LastWriteTime > csvFile.LastWriteTime)
                //    {
                //        XtraMessageBox.Show(sinleAsm.FullName + "文件生成时间大于" + csvFile.FullName);
                //        return;
                //    }
                //    if (dblAsm.LastWriteTime > csvFile.LastWriteTime)
                //    {
                //        XtraMessageBox.Show(dblAsm.FullName + "文件生成时间大于" + csvFile.FullName);
                //        return;
                //    }
                //    if (singleDxf.LastWriteTime > singleMfc.LastWriteTime)
                //    {
                //        XtraMessageBox.Show(singleMfc.FullName + "文件生成时间大于" + singleDxf.FullName);
                //        return;
                //    }
                //    if (dblDxf.LastWriteTime > dblMfc.LastWriteTime)
                //    {
                //        XtraMessageBox.Show(dblDxf.FullName + "文件生成时间大于" + dblMfc.FullName);
                //        return;
                //    }
                //    if (singledrw.LastWriteTime > singleDxf.LastWriteTime)
                //    {
                //        XtraMessageBox.Show(singledrw.FullName + "文件生成时间大于" + singleDxf.FullName);
                //        return;
                //    }
                //    if (dbldrw.LastWriteTime > dblDxf.LastWriteTime)
                //    {
                //        XtraMessageBox.Show(singledrw.FullName + "文件生成时间大于" + dblDxf.FullName);
                //        return;
                //    }

                //    //if (File.Exists(fileSngMfc))
                //    //    File.Copy(fileSngMfc, fileSrcSngFmc);//Sng fmc
                //    //else
                //    //{
                //    //    XtraMessageBox.Show(fileSngMfc + "程序不存在！");
                //    //    return;
                //    //}

                //    //if (File.Exists(fileDBLMfc))
                //    //    File.Copy(fileDBLMfc, fileSrcDblFmc);// Dbl fmc
                //    //else
                //    //{
                //    //    XtraMessageBox.Show(fileDBLMfc + "程序不存在！");
                //    //    return;

                //    //}
                //    File.Copy(fileSngMfc, fileSrcSngFmc);//Sng fmc
                //    File.Copy(fileDBLMfc, fileSrcDblFmc);// Dbl fmc
                //    if (File.Exists(fileFml))
                //        File.Delete(fileFml);


                //}
                //else if (machineType.ToLower() == "cnc")
                //{
                //    if (File.Exists(fileCncSngDxf))
                //        File.Delete(fileCncSngDxf);
                //    if (File.Exists(fileCncDblDxf))
                //        File.Delete(fileCncDblDxf);

                //    if (File.Exists(fileXSngDxf))
                //        File.Copy(fileXSngDxf, fileCncSngDxf);
                //    if (File.Exists(fileXDBLDxf))
                //        File.Copy(fileXDBLDxf, fileCncDblDxf);


                //    //删除
                //    if (File.Exists(fileFml))
                //        File.Delete(fileFml);
                //    if (File.Exists(fileSngMfc))
                //        File.Delete(fileSngMfc);
                //    if (File.Exists(fileDBLMfc))
                //        File.Delete(fileDBLMfc);
                //}
                //else if (machineType.ToLower() == "数控钻")
                //{
                //    if (File.Exists(fileXSngDxf))
                //        File.Copy(fileXSngDxf, fileSngDxf);
                //    if (File.Exists(fileXDBLDxf))
                //        File.Copy(fileXDBLDxf, fileDblDxf);
                //    //删除
                //    if (File.Exists(fileFml))
                //        File.Delete(fileFml);
                //    if (File.Exists(fileSngMfc))
                //        File.Delete(fileSngMfc);
                //    if (File.Exists(fileDBLMfc))
                //        File.Delete(fileDBLMfc);
                //}
                #endregion
              


                
                if (dtCsv.Rows.Count != 0)
                {

                    egdeList.Add(dtCsv.Rows[0]["封边_S1"].ToString());
                    egdeList.Add(dtCsv.Rows[0]["封边_S2"].ToString());
                    egdeList.Add(dtCsv.Rows[0]["封边_S3"].ToString());
                    egdeList.Add(dtCsv.Rows[0]["封边_S4"].ToString());
                }
                string Msg = "封边或开料尺寸匹配异常，数据如下，请检查！如SJ问题，请登记并通知SJ修改！\r\n\r\nNC数据：\r\n";
                string ncMsg = "";
                string bomMsg = "";
                //对比胶边信息
                bomMsg += "\r\n" + "BOM数据：" + "\r\n";
                DataTable dtBomInfo = Lamex.Base.BaseBuildSql.GetDataTableBySql(" select EDGE_CODE from [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_SJR] where  MATERIAL_NO='" + txtPart_No.Text + "' ");
                if (dtBomInfo.Rows.Count != 0)
                {
                    foreach (DataRow dr in dtBomInfo.Rows)
                    {
                        if (!string.IsNullOrEmpty(dr["EDGE_CODE"].ToString().Trim()))
                            bomMsg += dr["EDGE_CODE"].ToString() + "\r\n";
                    }
                }
                
                foreach (string s in egdeList)
                {
                    string str = "";
                    string si = s.Substring(s.Length - 2, 2).ToLower();
                    if (s.Substring(s.Length - 2, 2).ToLower() != "xx")
                    {
                        string repValue = "";
                        if (s.Substring(0, 2).ToLower() == "09")
                        {
                            repValue = s;
                            repValue = repValue.Replace("09", "12");
                        }
                        else
                            repValue = s;
                        if (repValue.Substring(repValue.Length - 3, 3).ToLower() == "###")
                        {
                                if (repValue.Substring(0, 1).ToLower() == "s")
                                {
                                    DataTable dtBOM = Lamex.Base.BaseBuildSql.GetDataTableBySql(" select * from [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_SJR] where convert(nvarchar(4),[EDGE_CODE])='" + repValue.Trim().Substring(0, 5) + "' and MATERIAL_NO='" + txtPart_No.Text + "' ");
                                    if (dtBOM.Rows.Count == 0)
                                    {
                                        ncMsg += repValue + "--不匹配\r\n";
                                    }
                                    else
                                    {
                                        ncMsg += repValue + "\r\n";
                                    }
                                }
                                else
                                {
                                    DataTable dtBOM = Lamex.Base.BaseBuildSql.GetDataTableBySql(" select * from [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_SJR] where convert(nvarchar(4),[EDGE_CODE])='" + repValue.Trim().Substring(0, 4) + "' and MATERIAL_NO='" + txtPart_No.Text + "' ");
                                    if (dtBOM.Rows.Count == 0)
                                    {
                                        ncMsg += repValue + "--不匹配\r\n";
                                    }
                                    else
                                    {
                                        ncMsg += repValue + "\r\n";
                                    }
                                }
                            
                        }
                        else
                        {
                                if (repValue.Substring(0, 1).ToLower() == "s")
                                {
                                    DataTable dtBOM = Lamex.Base.BaseBuildSql.GetDataTableBySql(" select * from [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_SJR] where EDGE_CODE like '%" + repValue.Trim().Substring(0, 8) + "%' and MATERIAL_NO='" + txtPart_No.Text + "' ");
                                    if (dtBOM.Rows.Count == 0)
                                    {
                                        ncMsg += repValue + "--不匹配\r\n";
                                    }
                                    else
                                    {
                                        ncMsg += repValue + "\r\n";
                                    }
                                }
                                else
                                {
                                    DataTable dtBOM = Lamex.Base.BaseBuildSql.GetDataTableBySql(" select * from [LamexMESManager].[dbo].[B_IE_PACKAGE_BOM_DATA_SJR] where EDGE_CODE = '" + repValue.Trim() + "' and MATERIAL_NO='" + txtPart_No.Text + "' ");
                                    if (dtBOM.Rows.Count == 0)
                                    {
                                        ncMsg += repValue + "--不匹配\r\n";
                                    }
                                    else
                                    {
                                        ncMsg += repValue + "\r\n";
                                    }
                                }
                             
                        }
                    }
                    else
                    {
                        ncMsg += s + "\r\n";
                    }

                }
                
                string errHeader = "\r\n"+ "尺寸对比异常结果如下：\r\n";
                string errMsgContext = "";
                string errFHeader= "";
                string errFMsgContext = "";

                //尺寸对比
                #region"尺寸对比"
                decimal NC_FINISH_WIDTH = 0;
                decimal NC_FINISH_DEPTH = 0;
                decimal NC_Dbl_WIDTH = 0;
                decimal NC_Dbl_DEPTH = 0;
                decimal NC_THICK = 0;
                string NC_GRAIN = "";
                decimal SJ_FINISH_WIDTH = 0;
                decimal SJ_FINISH_DEPTH = 0;
                decimal SJ_Dbl_WIDTH = 0;
                decimal SJ_Dbl_DEPTH = 0;
                decimal SJ_THICK = 0;
                string SJ_GRAIN = "";
                decimal SJ_CUTTED_WIDTH = 0;
                decimal SJ_CUTTED_DEPTH = 0;
                decimal NC_SNG_Width1 = 0;
                decimal NC_SNG_Width2 = 0;
                string NC_ConvertFlag = "";
                decimal SJ_GRAN_W = 0;
                decimal SJ_GRAN_D = 0;
                decimal SJ_GRAN_SIZE = 0;
                decimal NC_GRAN_W = 0;
                decimal NC_GRAN_D = 0;
                decimal NC_GRAN_SIZE = 0;
                //decimal NC_Dbl_Width1 = 0;
                //decimal NC_Dbl_Width2 = 0;



                NC_Convert_TaskListInfo SizeInfo = BaseFactory<NC_Convert_TaskList>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
                
                SJ_THICK = SizeInfo.THICK;
                SJ_GRAIN = SizeInfo.GRAIN;
                NC_SNG_Width1 = decimal.Parse(dtCsv.Rows[0]["阔度_1"].ToString());
                NC_SNG_Width2 = decimal.Parse(dtCsv.Rows[0]["阔度_2"].ToString());
                NC_GRAIN = dtCsv.Rows[0]["木纹方向"].ToString();
                if (SJ_GRAIN!=null)
                {
                    if (SJ_GRAIN.Trim() == "H")
                        SJ_GRAN_SIZE = SizeInfo.FINISH_WIDTH;
                    else
                        SJ_GRAN_SIZE = SizeInfo.FINISH_DEPTH;

                }
                else
                {
                    SJ_GRAN_SIZE = 0;
                }

                if (!NC_GRAIN.Trim().Contains("N"))
                {
                    if (NC_GRAIN.Trim().Contains("H"))
                        NC_GRAN_SIZE = NC_SNG_Width1;
                    else
                        NC_GRAN_SIZE = NC_SNG_Width2;
                    
                }
                else
                {
                    NC_GRAN_SIZE = 0;
                }


                NC_FINISH_WIDTH = decimal.Parse( dtCsv.Rows[0]["单开_W"].ToString());

                NC_FINISH_DEPTH = decimal.Parse(dtCsv.Rows[0]["单开_D"].ToString());
                if (dtCsv.Rows[0]["双开_W"].ToString()=="null" || string.IsNullOrEmpty(dtCsv.Rows[0]["双开_W"].ToString()))
                    NC_Dbl_WIDTH = 0;
                
                else
                    NC_Dbl_WIDTH = decimal.Parse(dtCsv.Rows[0]["双开_W"].ToString());
                if (dtCsv.Rows[0]["双开_D"].ToString()== "null" || string.IsNullOrEmpty(dtCsv.Rows[0]["双开_D"].ToString()))
                    NC_Dbl_DEPTH = 0;
                else
                    NC_Dbl_DEPTH =decimal.Parse(dtCsv.Rows[0]["双开_D"].ToString());


                

               
                if(NC_SNG_Width1< NC_SNG_Width2)
                {
                    decimal temp = NC_SNG_Width1;
                    NC_SNG_Width1 = NC_SNG_Width2;
                    NC_SNG_Width2 = temp;
                }
                NC_THICK = decimal.Parse(dtCsv.Rows[0]["厚度"].ToString());
                
                decimal fristHeight = 0;
                decimal fristWidth = 0;
                NC_FINISH_WIDTH = decimal.Parse(dtCsv.Rows[0]["单开_D"].ToString());
                NC_FINISH_DEPTH = decimal.Parse(dtCsv.Rows[0]["单开_W"].ToString());
                SJ_CUTTED_WIDTH = SizeInfo.CUTTED_WIDTH;
                SJ_CUTTED_DEPTH = SizeInfo.CUTTED_DEPTH;
                string iUpValue=  dtCsv.Rows[0]["封边_T1"].ToString();//封边_T1
                string iDownValue = dtCsv.Rows[0]["封边_T2"].ToString();//封边_T2
                string iLeftValue = dtCsv.Rows[0]["封边_T3"].ToString();//封边_T3
                string iRightValue = dtCsv.Rows[0]["封边_T4"].ToString();//封边_T4

                if (SizeInfo.FINISH_WIDTH>= SizeInfo.FINISH_DEPTH)//判断有无转向
                {
                    SJ_FINISH_WIDTH = SizeInfo.FINISH_WIDTH;
                    SJ_FINISH_DEPTH = SizeInfo.FINISH_DEPTH;
                    SJ_CUTTED_WIDTH = SizeInfo.CUTTED_WIDTH;
                    SJ_CUTTED_DEPTH = SizeInfo.CUTTED_DEPTH;
                    if (NC_ConvertFlag != "N")
                    {
                        if (NC_ConvertFlag == "V")
                            NC_ConvertFlag = "H";
                        else
                            NC_ConvertFlag = "V";
                    }
                    
                }
                else
                {
                    SJ_FINISH_WIDTH = SizeInfo.FINISH_DEPTH;
                    SJ_FINISH_DEPTH = SizeInfo.FINISH_WIDTH;
                        SJ_CUTTED_WIDTH = SizeInfo.CUTTED_DEPTH;
                        SJ_CUTTED_DEPTH = SizeInfo.CUTTED_WIDTH;
                    }

                //if (SizeInfo. >= SizeInfo.FINISH_DEPTH)//判断有无转向
                //{
                //    SJ_FINISH_WIDTH = SizeInfo.FINISH_WIDTH;
                //    SJ_FINISH_DEPTH = SizeInfo.FINISH_DEPTH;
                //    if (NC_ConvertFlag != "N")
                //    {
                //        if (NC_ConvertFlag == "V")
                //            NC_ConvertFlag = "H";
                //        else
                //            NC_ConvertFlag = "V";
                //    }

                //}
                //else
                //{
                //    SJ_FINISH_WIDTH = SizeInfo.FINISH_DEPTH;
                //    SJ_FINISH_DEPTH = SizeInfo.FINISH_WIDTH;
                //}
                if (NC_GRAN_SIZE != SJ_GRAN_SIZE)
                {
                    errFMsgContext += "木纹尺寸:SJ_" + SJ_GRAN_SIZE + "; NC_" + NC_GRAN_SIZE + "\r\n";
                    //XtraMessageBox.Show("木纹方向不一致！");
                    //return;
                }
                if (NC_THICK != SJ_THICK)
                {
                    errFMsgContext += "板厚:SJ_" + SJ_THICK + ";  NC_" + NC_THICK + "\r\n";
                    //XtraMessageBox.Show("厚度不一致！");
                    //return;
                }
                if (SJ_FINISH_WIDTH != NC_SNG_Width1)
                {
                    errFMsgContext += "成品长边:SJ_" + SJ_FINISH_WIDTH + "; NC_" + NC_SNG_Width1 + "\r\n";
                    //XtraMessageBox.Show("长度不一致！");
                    //return;
                }

                if (SJ_FINISH_DEPTH != NC_SNG_Width2)
                {
                    errFMsgContext += "成品短边:SJ_" + SJ_FINISH_DEPTH + "; NC_" + NC_SNG_Width2 + "\r\n";
                    //XtraMessageBox.Show("宽度不一致！");
                    //return;
                }

               
                

                //if (NC_THICK != SJ_THICK)
                //{
                //    errMsgContext += "厚度不一致:SJ_" + SJ_THICK + "; NC_" + NC_THICK + "\r\n";
                //    //XtraMessageBox.Show("厚度不一致！");
                //    //return;
                //}
                if (!string.IsNullOrEmpty(SizeInfo.DOUBLE_CUT_SIZE))//双开判断//
                                                                    //双开判断//
                {
                    

                    string[] strSpits = SizeInfo.DOUBLE_CUT_SIZE.Split('*');
                    if (strSpits.Count() == 3)
                    {
                        decimal sjHeight = decimal.Parse(strSpits[0].Replace("[", "").Replace("]", "").Trim());
                        decimal sjWidth = decimal.Parse(strSpits[1].Replace("[", "").Replace("]", "").Trim());
                        decimal sjThick = decimal.Parse(strSpits[2]);
                        if (sjHeight < sjWidth)
                        {
                            decimal temp = sjHeight;
                            sjHeight = sjWidth;
                            sjWidth = temp;
                        }

                        if (NC_Dbl_WIDTH < NC_Dbl_DEPTH)
                        {
                            decimal temp = NC_Dbl_WIDTH;
                            NC_Dbl_WIDTH = NC_Dbl_DEPTH;
                            NC_Dbl_DEPTH = temp;
                        }
                        if (sjHeight != NC_Dbl_WIDTH)
                        {
                            errMsgContext += "双开长边:SJ_" + sjHeight + "; NC_" + NC_Dbl_WIDTH + "\r\n";

                            //XtraMessageBox.Show("双开长度不一致！");
                            //return;
                        }
                        if (sjWidth != NC_Dbl_DEPTH)
                        {
                            errMsgContext += "双开短边:SJ_" + sjWidth + "; NC_" + NC_Dbl_DEPTH + "\r\n";
                            //  errMsgContext += "双开宽度不一致！\r\n";
                            //XtraMessageBox.Show("双开宽度不一致！");
                            //return;
                        }

                        //if (sjThick != NC_THICK)
                        //{
                        //    errMsgContext += "双开厚度不一致:SJ_" + sjThick + "和 NC_" + NC_THICK + "\r\n";
                        //    //errMsgContext += "双开宽度不一致！\r\n";
                        //    //XtraMessageBox.Show("双开厚度不一致！");
                        //    //return;
                        //}

                        //if (NC_ConvertFlag != SJ_GRAIN)
                        //{
                        //    errMsgContext += "木纹方向不一致SJ_" + SJ_GRAIN + " 和 NC_" + NC_ConvertFlag + "\r\n";
                        //    //XtraMessageBox.Show("木纹方向不一致！");
                        //    //return;
                        //}
                    }
                }
                if ("COMBIMA" == cuttingType)
                {

                    fristHeight = SJ_FINISH_WIDTH  + 4;
                    fristWidth = SJ_FINISH_DEPTH + 4;

                    //fristHeight = fristHeight - (decimal)ReValue(double.Parse(iLeftValue.ToLower().Replace("s", "").Trim()), double.Parse(iRightValue.ToLower().Replace("s", "").Trim())); 
                    //fristWidth = fristWidth - (decimal)ReValue(double.Parse(iUpValue.ToLower().Replace("s", "").Trim()), double.Parse(iDownValue.ToLower().Replace("s", "").Trim()));

                    fristHeight = fristHeight + SJ_CUTTED_WIDTH ;
                    fristWidth = fristWidth + SJ_CUTTED_DEPTH;

                    //rs = fristValue + "x" + fristSecond + "x" + cboxPart_Thick.Text;
                    
                    //if (NC_THICK != SJ_THICK)
                    //{
                    //    errMsgContext += "厚度不一致:SJ_"+ SJ_THICK   + "和 NC_" + NC_THICK + "\r\n";
                    //    //XtraMessageBox.Show("厚度不一致！");
                    //    //return;
                    //}
                    
                }
                else if ("BIMA" == cuttingType)
                {
                    fristHeight = SJ_FINISH_WIDTH ;
                    fristWidth = SJ_FINISH_DEPTH;
                    //if (dtTask.Rows[0]["DOUBLE_CUT_SIZE"].ToString() == "NULL" || dtTask.Rows[0]["DOUBLE_CUT_SIZE"].ToString().Trim() == "")
                    //{
                    //    if (fristHeight != NC_FINISH_DEPTH)
                    //    {
                    //        errMsgContext += "长度不一致:SJ_" + fristHeight + "和 NC_" + NC_FINISH_DEPTH + "\r\n";
                    //        //XtraMessageBox.Show("长度不一致！");
                    //        //return;
                    //    }
                    //    if (fristWidth != NC_FINISH_WIDTH)
                    //    {
                    //        errMsgContext += "宽度不一致:SJ_" + fristWidth + "NC_" + NC_FINISH_WIDTH + "\r\n";
                    //        //XtraMessageBox.Show("宽度不一致！");
                    //        //return;
                    //    }
                    //    //if (NC_THICK != SJ_THICK)
                    //    //{
                    //    //    errMsgContext += "厚度不一致:SJ_" + SJ_THICK  + "和 NC_" + NC_THICK + "\r\n";
                    //    //    //XtraMessageBox.Show("厚度不一致！");
                    //    //    //return;
                    //    //}
                    //    ////if (NC_ConvertFlag != SJ_GRAIN)
                    //    //{
                    //    //    errMsgContext += "木纹方向不一致SJ_" + SJ_GRAIN + "NC_" + NC_ConvertFlag   + "\r\n";
                    //    //    //XtraMessageBox.Show("木纹方向不一致！");
                    //    //    //return;
                    //    //}
                    //}
                    //else
                    //{
                    //    fristHeight = SJ_FINISH_DEPTH;
                    //    fristWidth = SJ_FINISH_WIDTH;
                    //    if (fristHeight != NC_FINISH_DEPTH)
                    //    {
                    //        errMsgContext += "长度不一致:SJ_" + fristHeight + "和 NC_" + NC_FINISH_DEPTH + "\r\n";
                    //        //XtraMessageBox.Show("长度不一致！");
                    //        //return;
                    //    }
                    //    if (fristWidth != NC_FINISH_WIDTH)
                    //    {
                    //        errMsgContext += "宽度不一致:SJ_" + fristWidth + "和 NC_" + NC_FINISH_WIDTH + "\r\n";
                    //        //XtraMessageBox.Show("宽度不一致！");
                    //        //return;
                    //    }
                    //    //if (NC_THICK != SJ_THICK)
                    //    //{
                    //    //    errMsgContext += "厚度不一致:SJ_" + SJ_THICK + "和 NC_" + NC_THICK + "\r\n";
                    //    //    //XtraMessageBox.Show("厚度不一致！");
                    //    //    //return;
                    //    //}
                    //    //if (NC_ConvertFlag != SJ_GRAIN)
                    //    //{
                    //    //    errMsgContext += "木纹方向不一致:SJ_" + SJ_GRAIN + "和 NC_" + NC_ConvertFlag + "\r\n";
                    //    //    //XtraMessageBox.Show("木纹方向不一致！");
                    //    //    //return;
                    //    //}
                        
                       
                        
                    //}
                }
                else if ("小板线" == cuttingType)
                {
                    fristHeight = SJ_FINISH_WIDTH ;
                    fristWidth = SJ_FINISH_DEPTH;
                    //fristHeight = decimal.Parse(txt_Width1.Text);
                    //fristWidth = decimal.Parse(txt_Width2.Text);

                    //fristHeight = fristHeight - (decimal)ReValue(double.Parse(cmb_LeftValue.Text.ToLower().Replace("s", "").Trim()), double.Parse(cmb_RightValue.Text.ToLower().Replace("s", "").Trim()));
                    //fristWidth = fristWidth - (decimal)ReValue(double.Parse(cmb_UpValue.Text.ToLower().Replace("s", "").Trim()), double.Parse(cmb_DownValue.Text.ToLower().Replace("s", "").Trim()));
                    // rs = fristValue + "x" + fristSecond + "x" + cboxPart_Thick.Text;
                    //fristHeight = decimal.Parse(txt_Width1.Text.ToLower().Replace("s", "").Trim()) + 2;
                    //fristWidth = decimal.Parse(txt_Width2.Text.ToLower().Replace("s", "").Trim()) + 2;
                    //fristHeight = fristHeight - (decimal)ReValue(double.Parse(iLeftValue.ToLower().Replace("s", "").Trim()), double.Parse(iRightValue.ToLower().Replace("s", "").Trim())); 
                    //fristWidth = fristWidth - (decimal)ReValue(double.Parse(iUpValue.ToLower().Replace("s", "").Trim()), double.Parse(iDownValue.ToLower().Replace("s", "").Trim()));
                    fristHeight = fristHeight + SJ_CUTTED_WIDTH ;
                    fristWidth = fristWidth + SJ_CUTTED_DEPTH;
                    //if (fristHeight != NC_FINISH_DEPTH)
                    //{
                    //    errMsgContext += "长度不一致:SJ_" + fristHeight + "和 NC_" + NC_FINISH_DEPTH + "\r\n";
                    //    //XtraMessageBox.Show("长度不一致！");
                    //    //return;
                    //}
                    //if (fristWidth != NC_FINISH_WIDTH)
                    //{
                    //    errMsgContext += "宽度不一致:SJ_" + fristWidth + "和 NC_" + NC_FINISH_WIDTH + "\r\n";
                    //    //XtraMessageBox.Show("宽度不一致！");
                    //    //return;
                    //}
                    //if (NC_THICK != SJ_THICK)
                    //{
                    //    errMsgContext += "厚度不一致:SJ_" + SJ_THICK  + "和 NC_" + NC_THICK + "\r\n";
                    //    //XtraMessageBox.Show("厚度不一致！");
                    //    //return;
                    //}
                    //if (NC_ConvertFlag != SJ_GRAIN)
                    //{
                    //    errMsgContext += "木纹方向不一致:SJ_" + SJ_GRAIN + "和 NC_" + NC_ConvertFlag  + "\r\n";
                    //    //XtraMessageBox.Show("木纹方向不一致！");
                    //    //return;
                    //}
                }
                else if ("斜边线" == cuttingType)
                {
                    fristHeight = SJ_FINISH_WIDTH  + 2;
                    fristWidth = SJ_FINISH_DEPTH + 2;
                    //fristHeight = decimal.Parse(txt_Width1.Text.ToLower().Replace("s", "").Trim()) + 2;
                    //fristWidth = decimal.Parse(txt_Width2.Text.ToLower().Replace("s", "").Trim()) + 2;
                    //fristHeight = fristHeight - (decimal)ReValue(double.Parse(iLeftValue.ToLower().Replace("s", "").Trim()), double.Parse(iRightValue.ToLower().Replace("s", "").Trim()));
                    //fristWidth = fristWidth - (decimal)ReValue(double.Parse(iUpValue.ToLower().Replace("s", "").Trim()), double.Parse(iDownValue.ToLower().Replace("s", "").Trim()));
                    fristHeight = fristHeight + SJ_CUTTED_WIDTH    ;
                    fristWidth = fristWidth + SJ_CUTTED_DEPTH;
                    //if (fristHeight != NC_FINISH_DEPTH)
                    //{
                    //    errMsgContext += "长度不一致:SJ_" + fristHeight + "和 NC_" + NC_FINISH_DEPTH + "\r\n";
                    //    //XtraMessageBox.Show("长度不一致！");
                    //    //return;
                    //}
                    //if (fristWidth != NC_FINISH_WIDTH)
                    //{
                    //    errMsgContext += "宽度不一致:SJ_" + fristWidth + "和 NC_" + NC_FINISH_WIDTH + "\r\n";
                    //    //XtraMessageBox.Show("宽度不一致！");
                    //    //return;
                    //}
                    //if (NC_THICK != SJ_THICK)
                    //{
                    //    errMsgContext += "厚度不一致:SJ_" + SJ_THICK + "和 NC_" + NC_THICK  + "\r\n";
                    //    //XtraMessageBox.Show("厚度不一致！");
                    //    //return;
                    //}
                    //if (NC_ConvertFlag != SJ_GRAIN)
                    //{
                    //    errMsgContext += "木纹方向不一致:SJ_" + SJ_GRAIN + "和 NC_" + NC_ConvertFlag  + "\r\n";
                    //    //XtraMessageBox.Show("木纹方向不一致！");
                    //    //return;
                    //}
                }

                if (fristHeight < fristWidth)
                {
                    decimal temp = fristHeight;
                    fristHeight = fristWidth;
                    fristWidth = temp;
                }
                if (NC_FINISH_WIDTH  < NC_FINISH_DEPTH)
                {
                    decimal temp = NC_FINISH_WIDTH;
                    NC_FINISH_WIDTH = NC_FINISH_DEPTH;
                    NC_FINISH_DEPTH = temp;
                }
                if (fristHeight != NC_FINISH_WIDTH)
                {
                    errMsgContext += "单开长边:SJ_" + fristHeight + ";  NC_" + NC_FINISH_WIDTH + "\r\n";
                    //XtraMessageBox.Show("长度不一致！");
                    //return;
                }

                if (fristWidth != NC_FINISH_DEPTH)
                {
                    errMsgContext += "单开短边:SJ_" + fristWidth + "; NC_" + NC_FINISH_DEPTH + "\r\n";
                    //XtraMessageBox.Show("宽度不一致！");
                    //return;
                }
                string showErrMeg = "";
                
                if (ncMsg.Contains("不匹配")||!string.IsNullOrEmpty(errMsgContext) || !string.IsNullOrEmpty(errFMsgContext))
                {
                    if (ncMsg.Contains("不匹配"))
                    {
                        showErrMeg += Msg + ncMsg + bomMsg;
                    }
                    if (!string.IsNullOrEmpty(errFMsgContext))
                    {
                        showErrMeg += errHeader+ errFMsgContext;
                    }
                    if (!string.IsNullOrEmpty(errMsgContext))
                    {
                        if (showErrMeg.Contains("尺寸对比"))
                            showErrMeg += errMsgContext;
                        else
                            showErrMeg += errHeader + errMsgContext;
                    }



                    XtraMessageBox.Show(showErrMeg);
                    return;
                }
                    #endregion

                    //加控制条件
                    #region"hide"
                    if (machineType.ToLower() == "puh")
                    {


                        FileInfo singledrw = new FileInfo(singleTp1DrwPath);//时间对比
                        FileInfo singleDxf = new FileInfo(fileXSngDxf);

                        FileInfo singleMfc = new FileInfo(fileSngMfc);
                        FileInfo sinleAsm = new FileInfo(singleTp1AsmPath);
                        FileInfo csvFile = new FileInfo(path);

                        FileInfo dblMfc = new FileInfo(fileDBLMfc);
                        FileInfo dblDxf = new FileInfo(fileXDBLDxf);
                        if (sinleAsm.LastWriteTime > csvFile.LastWriteTime)
                        {
                            XtraMessageBox.Show(sinleAsm.Name + "文件生成时间大于" + csvFile.Name);
                            return;
                        }

                        //if (singleDxf.LastWriteTime > singleMfc.LastWriteTime)
                        //{
                        //    XtraMessageBox.Show(singleDxf.FullName + "文件生成时间大于" + singleMfc.FullName);
                        //    return;
                        //}
                        if (singledrw.LastWriteTime > singleDxf.LastWriteTime)
                        {
                            XtraMessageBox.Show(singledrw.Name + "文件生成时间大于" + singleDxf.Name);
                            return;
                        }

                        if (!File.Exists(filePath))
                        {
                            XtraMessageBox.Show("FML程序不存在！");
                            return;
                        }
                        
                        FileInfo singlefml = new FileInfo(filePath);
                        if (singleDxf.LastWriteTime > singlefml.LastWriteTime)
                        {
                            XtraMessageBox.Show(singleDxf.Name + "文件生成时间大于" + singlefml.Name);
                            return;
                        }
                        if (File.Exists(fileFml))//删除原有FML
                            File.Delete(fileFml);
                        File.Move(filePath, fileFml);//c-target


                        if (File.Exists(fileSngMfc))
                            File.Delete(fileSngMfc);
                    }
                    else if (machineType.ToLower() == "bima")
                    {
                        if (dtTask.Rows[0]["DOUBLE_CUT_SIZE"].ToString() == "NULL" || dtTask.Rows[0]["DOUBLE_CUT_SIZE"].ToString().Trim() == "")
                        {
                            if (!File.Exists(fileSngMfc))
                            {
                                XtraMessageBox.Show("SngMfc程序不存在！");
                                return;
                            }
                            if (!File.Exists(fileXSngDxf))
                            {
                                XtraMessageBox.Show("SngDxf程序不存在！");
                                return;
                            }
                        }
                        else
                        {
                            if (!File.Exists(fileSngMfc))
                            {
                                XtraMessageBox.Show("SngMfc程序不存在！");
                                return;
                            }
                            if (!File.Exists(fileXSngDxf))
                            {
                                XtraMessageBox.Show("SngDxf程序不存在！");
                                return;
                            }
                            if (!File.Exists(fileDBLMfc))
                            {
                                XtraMessageBox.Show("DblMfc程序不存在！");
                                return;
                            }

                            if (!File.Exists(fileXSngDxf))
                            {
                                XtraMessageBox.Show("dblLDxf程序不存在！");
                                return;
                            }
                        }


                        FileInfo singledrw = new FileInfo(singleTp1DrwPath);//时间对比
                        FileInfo dbldrw = new FileInfo(doubleTp1DrwPath);
                        FileInfo singleDxf = new FileInfo(fileXSngDxf);
                        FileInfo singlefml = new FileInfo(fileFml);
                        FileInfo singleMfc = new FileInfo(fileSngMfc);
                        FileInfo sinleAsm = new FileInfo(singleTp1AsmPath);
                        FileInfo dblAsm = new FileInfo(doubleTp1AsmPath);
                        FileInfo csvFile = new FileInfo(path);

                        FileInfo dblMfc = new FileInfo(fileDBLMfc);
                        FileInfo dblDxf = new FileInfo(fileXDBLDxf);
                        if (sinleAsm.LastWriteTime > csvFile.LastWriteTime)
                        {
                            XtraMessageBox.Show(sinleAsm.Name + "文件生成时间大于" + csvFile.Name);
                            return;
                        }
                        if (dblAsm.LastWriteTime > csvFile.LastWriteTime)
                        {
                            XtraMessageBox.Show(dblAsm.Name + "文件生成时间大于" + csvFile.Name);
                            return;
                        }
                        if (singleDxf.LastWriteTime > singleMfc.LastWriteTime)
                        {
                            XtraMessageBox.Show(singleDxf.Name + "文件生成时间大于" + singleMfc.Name);
                            return;
                        }

                        if (singledrw.LastWriteTime > singleDxf.LastWriteTime)
                        {
                            XtraMessageBox.Show(singledrw.Name + "文件生成时间大于" + singleDxf.Name);
                            return;
                        }
                        if (dbldrw.LastWriteTime > dblDxf.LastWriteTime)
                        {
                            XtraMessageBox.Show(singledrw.Name + "文件生成时间大于" + dblDxf.Name);
                            return;
                        }
                        if (dblDxf.LastWriteTime > dblMfc.LastWriteTime)
                        {
                            XtraMessageBox.Show(dblDxf.Name + "文件生成时间大于" + dblMfc.Name);
                            return;
                        }
                    }
                    else
                    {
                        //删除
                        if (File.Exists(fileFml))
                            File.Delete(fileFml);
                        if (File.Exists(fileSngMfc))
                            File.Delete(fileSngMfc);
                        if (File.Exists(fileDBLMfc))
                            File.Delete(fileDBLMfc);
                    }
                    #endregion
                    if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                        MCreoDll.setDir();
                    DirectoryInfo di = new DirectoryInfo(movePath);//移动文件
                    di.MoveTo(nC_DK_SJ01 + @"\" + PartNo);
                    
                    if (BaseFactory<NC_Convert_ProcessRecord>.Instance.Update(bll))
                    {
                        //需要解除文件权限\
                        
                        XtraMessageBox.Show("NC成功确认！");
                        return;
                    }
                    else
                    {
                        XtraMessageBox.Show("NC确认失败！");
                        return;
                    }


                }


            }
            catch(Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }


        }
        
        private void cmb_Up_TextChanged(object sender, EventArgs e)
        {
            if (cmb_Up.Text == "PVC_XXX_不封" || cmb_Up.Text == "PVC_NIL_不适用")
            {
                cmb_UpValue.Properties.Items.Clear();
                cmb_UpValue.Properties.Items.Add(" ");
                cmb_UpValue.Properties.Items.Add("0");
                cmb_UpValue.Properties.Items.Add("0.6");
                cmb_UpValue.Properties.Items.Add("2");
                cmb_UpValue.Properties.Items.Add("S0.6");
                cmb_UpValue.Properties.Items.Add("S2");
            }
            else
            {
                cmb_UpValue.Properties.Items.Clear();
                cmb_UpValue.Properties.Items.Add(" ");
                cmb_UpValue.Properties.Items.Add("0.6");
                cmb_UpValue.Properties.Items.Add("2");
                cmb_UpValue.Properties.Items.Add("S0.6");
                cmb_UpValue.Properties.Items.Add("S2");
            }

            if (string.IsNullOrEmpty(cmb_Up.Text)) return;
            if (cmb_Up.Text.Length > 9)
            {
                DataTable dt = BaseBuildSql.GetDataTableBySql(" select * from NC_Convert_Edge_Material_Info where EDGE_CODE='" + cmb_Up.Text + "'");
                if (dt.Rows.Count != 0)
                {

                    if (decimal.Parse(dt.Rows[0]["EDGE_THICKNESS"].ToString()) == 0)
                    {
                        if (cmb_Up.Text == "PVC_XXX_不封")
                        {
                            cmb_UpValue.Text = "0";
                            cmb_UpValue.ReadOnly = true;
                        }
                            
                        else if (cmb_Up.Text == "PVC_NIL_不适用")
                        {
                            cmb_UpValue.Text = "0";
                            cmb_UpValue.ReadOnly = true;
                        }
                            
                        else
                        {
                            cmb_UpValue.Text = "";
                            cmb_UpValue.ReadOnly = false;
                        }
                            
                    }
                    else
                    {
                        cmb_UpValue.ReadOnly = false;
                        cmb_UpValue.Text = dt.Rows[0]["EDGE_THICKNESS"].ToString();

                    }
                    UpoldStr = cmb_Up.Text;
                }
                
            }
            UpoldValue = "";
            if (nCSatuts == "审核中") cmb_UpValue.ReadOnly = true;
        }

        private void cmb_Down_TextChanged(object sender, EventArgs e)
        {
            if (cmb_Down.Text == "PVC_XXX_不封" || cmb_Down.Text == "PVC_NIL_不适用")
            {
                cmb_DownValue.Properties.Items.Clear();
                cmb_DownValue.Properties.Items.Add(" ");
                cmb_DownValue.Properties.Items.Add("0");
                cmb_DownValue.Properties.Items.Add("0.6");
                cmb_DownValue.Properties.Items.Add("2");
                cmb_DownValue.Properties.Items.Add("S0.6");
                cmb_DownValue.Properties.Items.Add("S2");
            }
            else
            {
                cmb_DownValue.Properties.Items.Clear();
                cmb_DownValue.Properties.Items.Add(" ");
                cmb_DownValue.Properties.Items.Add("0.6");
                cmb_DownValue.Properties.Items.Add("2");
                cmb_DownValue.Properties.Items.Add("S0.6");
                cmb_DownValue.Properties.Items.Add("S2");
            }

            if (string.IsNullOrEmpty(cmb_Down.Text)) return;
            if (cmb_Down.Text.Length > 9)
            {
                DataTable dt = BaseBuildSql.GetDataTableBySql(" select * from NC_Convert_Edge_Material_Info where EDGE_CODE='" + cmb_Down.Text + "'");
                if (dt.Rows.Count != 0)
                {

                    if (decimal.Parse(dt.Rows[0]["EDGE_THICKNESS"].ToString()) == 0)
                    {
                        if (cmb_Down.Text == "PVC_XXX_不封")
                        {
                            cmb_DownValue.Text = "0";
                            cmb_DownValue.ReadOnly = true;
                        }
                            
                        else if (cmb_Down.Text == "PVC_NIL_不适用")
                        {
                            cmb_DownValue.Text = "0";
                            cmb_DownValue.ReadOnly = true;
                        }
                            
                        else
                        {
                            cmb_DownValue.Text = "";
                            cmb_DownValue.ReadOnly = false;
                        }
                            
                    }
                    else
                    {
                        cmb_DownValue.ReadOnly = true;
                        cmb_DownValue.Text = dt.Rows[0]["EDGE_THICKNESS"].ToString();
                    }
                    DownOldStr = cmb_Down.Text;
                }
                
            }

            if (nCSatuts == "审核中") cmb_DownValue.ReadOnly = true;
        }

        private void cmb_Left_TextChanged(object sender, EventArgs e)
        {
            if (cmb_Left.Text == "PVC_XXX_不封" || cmb_Left.Text == "PVC_NIL_不适用")
            {
                cmb_LeftValue.Properties.Items.Clear();
                cmb_LeftValue.Properties.Items.Add(" ");
                cmb_LeftValue.Properties.Items.Add("0");
                cmb_LeftValue.Properties.Items.Add("0.6");
                cmb_LeftValue.Properties.Items.Add("2");
                cmb_LeftValue.Properties.Items.Add("S0.6");
                cmb_LeftValue.Properties.Items.Add("S2");
            }
            else
            {
                cmb_LeftValue.Properties.Items.Clear();
                cmb_LeftValue.Properties.Items.Add(" ");
                cmb_LeftValue.Properties.Items.Add("0.6");
                cmb_LeftValue.Properties.Items.Add("2");
                cmb_LeftValue.Properties.Items.Add("S0.6");
                cmb_LeftValue.Properties.Items.Add("S2");
            }

            if (string.IsNullOrEmpty(cmb_Left.Text)) return;
            if (cmb_Left.Text.Length > 9)
            {

                DataTable dt = BaseBuildSql.GetDataTableBySql(" select * from NC_Convert_Edge_Material_Info where EDGE_CODE='" + cmb_Left.Text + "'");
                if (dt.Rows.Count != 0)
                {

                    if (decimal.Parse(dt.Rows[0]["EDGE_THICKNESS"].ToString()) == 0)
                    {
                        if (cmb_Left.Text == "PVC_XXX_不封")
                        {
                            cmb_LeftValue.Text = "0";
                            cmb_LeftValue.ReadOnly = true;
                        }
                        
                        else if (cmb_Left.Text == "PVC_NIL_不适用")
                        {
                            cmb_LeftValue.Text = "0";
                            cmb_LeftValue.ReadOnly = true;
                        }
                            
                        else
                        {
                            cmb_LeftValue.ReadOnly = false;
                            cmb_LeftValue.Text = "";
                        }
                            
                    }
                    else
                    {
                        cmb_LeftValue.ReadOnly = false;
                        cmb_LeftValue.Text = dt.Rows[0]["EDGE_THICKNESS"].ToString();
                    }
                    LeftOldStr = cmb_Left.Text;

                }
                
            }

            if (nCSatuts == "审核中") cmb_LeftValue.ReadOnly = true;
        }
        

        private void cmb_Right_TextChanged(object sender, EventArgs e)
        {
            if (cmb_Right.Text == "PVC_XXX_不封" || cmb_Right.Text == "PVC_NIL_不适用")
            {
                cmb_RightValue.Properties.Items.Clear();
                cmb_RightValue.Properties.Items.Add(" ");
                cmb_RightValue.Properties.Items.Add("0");
                cmb_RightValue.Properties.Items.Add("0.6");
                cmb_RightValue.Properties.Items.Add("2");
                cmb_RightValue.Properties.Items.Add("S0.6");
                cmb_RightValue.Properties.Items.Add("S2");
            }
            else
            {
                cmb_RightValue.Properties.Items.Clear();
                cmb_RightValue.Properties.Items.Add(" ");
                cmb_RightValue.Properties.Items.Add("0.6");
                cmb_RightValue.Properties.Items.Add("2");
                cmb_RightValue.Properties.Items.Add("S0.6");
                cmb_RightValue.Properties.Items.Add("S2");
            }
            if (cmb_Right.Text.Length > 9)
            {
                if (cmb_Right.Text == RightOldStr) return;
                DataTable dt = BaseBuildSql.GetDataTableBySql(" select * from NC_Convert_Edge_Material_Info where EDGE_CODE='" + cmb_Right.Text + "'");
                if (dt.Rows.Count != 0)
                {

                    if (decimal.Parse(dt.Rows[0]["EDGE_THICKNESS"].ToString()) == 0)
                    {
                        if (cmb_Right.Text == "PVC_XXX_不封")
                        {
                            cmb_RightValue.ReadOnly = true;
                            cmb_RightValue.Text = "0";
                            
                        }   
                        else if (cmb_Right.Text == "PVC_NIL_不适用")
                        {
                            cmb_RightValue.ReadOnly = true;
                            cmb_RightValue.Text = "0";
                        }
                        else
                        {
                            cmb_RightValue.ReadOnly = false;
                            cmb_RightValue.Text = "";
                        }
                            
                    }
                    else
                    {
                        cmb_RightValue.ReadOnly = false;
                        cmb_RightValue.Text = dt.Rows[0]["EDGE_THICKNESS"].ToString();
                    }
                    RightOldStr = cmb_Right.Text;
                }
                if (nCSatuts == "审核中") cmb_RightValue.ReadOnly = true;
            }
        }

        /// 计算字符串中子串出现的次数
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="substring">子串</param>
        /// <returns>出现的次数</returns>
        static int SubstringCount(string str, string substring)
        {
            if (str.Contains(substring))
            {
                string strReplaced = str.Replace(substring, "");
                int count= (str.Length - strReplaced.Length) / substring.Length;
                if ((strReplaced.Length > 0 && count >0)|| (strReplaced.Length == 0 && count > 1)|| (strReplaced.Length == 0 && count == 0))
                    count = 2;
                else
                    count = 1;
                return count;
            }

            return 0;
        }

        private void cmb_UpValue_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_UpValue.Text)) return;
            //if (cmb_UpValue.Text == UpoldValue) return;
            if (string.IsNullOrEmpty(cmb_Up.Text))
            {
                XtraMessageBox.Show("胶边不能为空！");
                UpoldValue = "";
                cmb_UpValue.Text = "";
                
            }

            if (UpoldValue == "")
                UpoldValue = cmb_UpValue.Text;
            //else
            //{
            //    int a = cmb_UpValue.Text.Split(new string[] { UpoldValue }, StringSplitOptions.None).Length - 1;
            //}

        }

        private void cmb_DownValue_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_DownValue.Text)) return;
            //if (cmb_UpValue.Text == UpoldValue) return;
            if (string.IsNullOrEmpty(cmb_Down.Text))
            {
                XtraMessageBox.Show("胶边不能为空！");
                DownOldValue = "";
                cmb_DownValue.Text = "";

            }

            if (DownOldValue == "")
                DownOldValue = cmb_DownValue.Text;
        }

        private void cmb_LeftValue_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_LeftValue.Text)) return;
            //if (cmb_UpValue.Text == UpoldValue) return;
            if (string.IsNullOrEmpty(cmb_Left.Text))
            {
                XtraMessageBox.Show("胶边不能为空！");
                LeftOldValue = "";
                cmb_LeftValue.Text = "";

            }

            if (LeftOldValue == "")
                LeftOldValue = cmb_LeftValue.Text;
        }

        private void cmb_RightValue_TextChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_RightValue.Text)) return;
            if (string.IsNullOrEmpty(cmb_Right.Text))
            {
                XtraMessageBox.Show("胶边不能为空！");
                RightOldValue = "";
                cmb_RightValue.Text = "";

            }

            if (RightOldValue == "")
                RightOldValue = cmb_RightValue.Text;
        }

        /// <summary>
        /// change form up and down
        /// </summary>
        /// <param name="sender"></param>
        //public override void DOChange(IButtonInfo sender)
        //{
            
        //        base.DOChange(sender);
        //}

        

        private void pictureEdit2_DoubleClick(object sender, EventArgs e)
        {
            if (isShow == true)
            {
                panelControl_Top.Hide();
                //panelControl_Top.AutoSize = true;
                //panelControl_Top.Height = 30;
                isShow = false;
            }
            else
            {
                panelControl_Top.Show();
                //panelControl_Top.AutoSize = true;
                //panelControl_Top.Height = 142;
                isShow = true;
            }
        }

        private void cmb_Up_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
        {

        }

        private void cmb_Up_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Up.Text)) return;
            if (cmb_Up.Text.Length > 9)
            {
                if (!string.IsNullOrEmpty(UpoldStr))
                {
                    if (SubstringCount(cmb_Up.Text, UpoldStr) > 1)
                    {
                        XtraMessageBox.Show("胶边重复");
                        cmb_Up.Text = "";
                        cmb_Up.EditValue = "";
                        UpoldStr = cmb_Up.Text;
                        return;
                    }
                    if(cmb_Up.Text!= UpoldStr)
                        cmb_Up.EditValue = "";

                }
                //else
                //    UpoldStr = cmb_Up.Text;
            }
        }

        private void cmb_Down_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Down.Text)) return;
            if (cmb_Down.Text.Length > 9)
            {

                if (!string.IsNullOrEmpty(DownOldStr))
                {
                    if (SubstringCount(cmb_Down.Text, DownOldStr) > 1)
                    {
                        XtraMessageBox.Show("胶边重复");
                        cmb_Down.Text = "";
                        cmb_DownValue.Text = "";
                        DownOldStr = cmb_Down.Text;
                    }
                }
                
            }
        }

        private void cmb_Left_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Left.Text)) return;
            if (cmb_Left.Text.Length > 9)
            {
                if (!string.IsNullOrEmpty(LeftOldStr))
                {
                    if (SubstringCount(cmb_Left.Text, LeftOldStr) > 1)
                    {
                        XtraMessageBox.Show("胶边重复");
                        cmb_Left.Text = "";
                        cmb_LeftValue.Text = "";
                        LeftOldStr = cmb_Left.Text;
                        return;
                    }
                }
            }
        }

        private void cmb_Right_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_Right.Text)) return;
            if (cmb_Right.Text.Length > 9)
            {
                if (!string.IsNullOrEmpty(RightOldStr))
                {
                    if (SubstringCount(cmb_Right.Text, RightOldStr) > 1)
                    {
                        XtraMessageBox.Show("胶边重复");
                        cmb_Right.Text = "";
                        cmb_RightValue.Text = "";
                        RightOldStr = cmb_Right.Text;
                        return;
                    }
                }
            }
        }

        
        private void cmb_UpValue_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_UpValue.Text)) return;
            int len = 0;
            if (!string.IsNullOrEmpty(UpoldValue))
            {
                int a = cmb_UpValue.Text.Split(new string[] { UpoldValue }, StringSplitOptions.None).Length - 1;
                if (cmb_UpValue.Text.Length > UpoldValue.Length)
                    len = 1;
                if (a>=1&&len==1)
                {
                    XtraMessageBox.Show("数值选择重复");
                    UpoldValue = "";
                    cmb_UpValue.Text = "";
                    //cmb_UpValue.Text = "";
                    
                    //return;
                }
            }
            
        }

        private void cmb_DownValue_KeyUp(object sender, KeyEventArgs e)
        {

            if (string.IsNullOrEmpty(cmb_DownValue.Text)) return;
            int len = 0;
            if (!string.IsNullOrEmpty(DownOldValue))
            {
                int a = cmb_DownValue.Text.Split(new string[] { DownOldValue }, StringSplitOptions.None).Length - 1;
                if (cmb_DownValue.Text.Length > DownOldValue.Length)
                    len = 1;
                if (a >= 1 && len == 1)
                {
                    XtraMessageBox.Show("数值选择重复");
                    DownOldValue = "";
                    cmb_DownValue.Text = "";
                    //cmb_UpValue.Text = "";

                    //return;
                }
            }
        }

        private void cmb_LeftValue_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_LeftValue.Text)) return;
            int len = 0;
            if (!string.IsNullOrEmpty(LeftOldValue))
            {
                int a = cmb_LeftValue.Text.Split(new string[] { LeftOldValue }, StringSplitOptions.None).Length - 1;
                if (cmb_LeftValue.Text.Length > LeftOldValue.Length)
                    len = 1;
                if (a >= 1 && len == 1)
                {
                    XtraMessageBox.Show("数值选择重复");
                    LeftOldValue = "";
                    cmb_LeftValue.Text = "";
                    //cmb_UpValue.Text = "";

                    //return;
                }
            }
        }

        private void cmb_RightValue_KeyUp(object sender, KeyEventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_RightValue.Text)) return;
            int len = 0;
            if (!string.IsNullOrEmpty(RightOldValue))
            {
                int a = cmb_RightValue.Text.Split(new string[] { RightOldValue }, StringSplitOptions.None).Length - 1;
                if (cmb_RightValue.Text.Length > RightOldValue.Length)
                    len = 1;
                if (a >= 1 && len == 1)
                {
                    XtraMessageBox.Show("数值选择重复");
                    RightOldValue = "";
                    cmb_RightValue.Text = "";
                    //cmb_UpValue.Text = "";

                    //return;
                }
            }
        }

        private void cmb_UpValue_SelectedIndexChanged(object sender, EventArgs e)
        {
            //UpoldValue = "";
        }

        private void ucShowPic1_DoubleClick(object sender, EventArgs e)
        {
           
        }

        private void ucShowPic1_UcDoubleClick(object sender, EventArgs e)
        {
            pictureEdit2_DoubleClick(null, null);
        }

        private void sbtnRefresh_Click(object sender, EventArgs e)
        {

        }

        private void cmbNum_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void cmbWidthType_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(cmbNum.Text))
            //{
            //    XtraMessageBox.Show("数据值不能空！");
            //    return;
            //}
            //if (cmbWidthType.Text=="空")
            //{
            //    cmbNum.Text = "0";
            //}
            //else if (cmbWidthType.Text == "阔度1方向" )
            //{
            //    if (cmbNum.Text == "2")
            //        txt_Width1.Text = (widthNm1 + 2).ToString();
            //    if (cmbNum.Text == "4")
            //        txt_Width1.Text = (widthNm1 + 4).ToString();
            //}
            //else if (cmbWidthType.Text == "阔度2方向" )
            //{
            //    if (cmbNum.Text == "2")
            //        txt_Width2.Text = (widthNm2 + 2).ToString();
            //    if (cmbNum.Text == "4")
            //        txt_Width2.Text = (widthNm2 + 4).ToString();
            //}

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\MESNC.exe;L:\Share\MurphyMin\CreoBox\");
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            FileStream fs = null;
            StreamWriter sw = null;
            try
            {


                if (false == AlertMsg()) return;
                if (string.IsNullOrEmpty(rountingType))
                {
                    XtraMessageBox.Show("工艺路线不能为空!");
                    return;
                }

                if (string.IsNullOrEmpty(cmb_Up.Text))
                {
                    XtraMessageBox.Show("胶边上不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(cmb_Down.Text))
                {
                    XtraMessageBox.Show("胶边下不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(cmb_Left.Text))
                {
                    XtraMessageBox.Show("胶边左不能为空!");
                    return;
                }

                if (string.IsNullOrEmpty(cmb_Right.Text))
                {
                    XtraMessageBox.Show("胶边右不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(cmb_UpValue.Text))
                {
                    XtraMessageBox.Show("胶边上值不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(cmb_DownValue.Text))
                {
                    XtraMessageBox.Show("胶边下值不能为空!");
                    return;
                }
                if (string.IsNullOrEmpty(cmb_LeftValue.Text))
                {
                    XtraMessageBox.Show("胶边左值不能为空!");
                    return;
                }

                if (string.IsNullOrEmpty(cmb_RightValue.Text))
                {
                    XtraMessageBox.Show("胶边右值不能为空!");
                    return;
                }
                //
                if (!(cmb_Up.Text == "PVC_NIL_不适用" || cmb_Up.Text == "PVC_XXX_不封"))
                {
                    if (cmb_UpValue.Text == "0")
                    {
                        XtraMessageBox.Show("胶边上不能为0!");
                        return;
                    }
                }
                if (!(cmb_Down.Text == "PVC_NIL_不适用" || cmb_Down.Text == "PVC_XXX_不封"))
                {
                    if (cmb_DownValue.Text == "0")
                    {
                        XtraMessageBox.Show("胶边下不能为0!");
                        return;
                    }
                }
                if (!(cmb_Left.Text == "PVC_NIL_不适用" || cmb_Left.Text == "PVC_XXX_不封"))
                {
                    if (cmb_LeftValue.Text == "0")
                    {
                        XtraMessageBox.Show("胶边左不能为0!");

                        return;
                    }
                }
                if (!(cmb_Right.Text == "PVC_NIL_不适用" || cmb_Right.Text == "PVC_XXX_不封"))
                {
                    if (cmb_RightValue.Text == "0")
                    {
                        XtraMessageBox.Show("胶边右不能为0!");
                        return;
                    }
                }
                DataTable dtUp = Lamex.Base.BaseBuildSql.GetDataTableBySql("select EDGE_CODE from [dbo].[NC_Convert_Edge_Material_Info]  where EDGE_CODE='" + cmb_Up.Text + "'");
                if (dtUp.Rows.Count == 0)
                {
                    XtraMessageBox.Show("胶边右不存在!");
                    return;
                }
                DataTable dtDown = Lamex.Base.BaseBuildSql.GetDataTableBySql("select EDGE_CODE from [dbo].[NC_Convert_Edge_Material_Info]  where EDGE_CODE='" + cmb_Down.Text + "'");
                if (dtDown.Rows.Count == 0)
                {
                    XtraMessageBox.Show("胶边下不存在!");
                    return;
                }
                DataTable dtLeft = Lamex.Base.BaseBuildSql.GetDataTableBySql("select EDGE_CODE from [dbo].[NC_Convert_Edge_Material_Info]  where EDGE_CODE='" + cmb_Left.Text + "'");
                if (dtLeft.Rows.Count == 0)
                {
                    XtraMessageBox.Show("胶边左不存在!");
                    return;
                }
                DataTable dtRight = Lamex.Base.BaseBuildSql.GetDataTableBySql("select EDGE_CODE from [dbo].[NC_Convert_Edge_Material_Info]  where EDGE_CODE='" + cmb_Right.Text + "'");
                if (dtRight.Rows.Count == 0)
                {
                    XtraMessageBox.Show("胶边右不存在!");
                    return;
                }
                if (string.IsNullOrEmpty(cmbWidth1.Text)) cmbWidth1.Text = "0";
                if (string.IsNullOrEmpty(cmbWidth2.Text)) cmbWidth2.Text = "0";
                if (string.IsNullOrEmpty(cmbThickness.Text)) cmbThickness.Text = "0";

                if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                {
                    Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\NCCSV.exe;L:\Share\MurphyMin\CreoBox\");
                    Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\NCDXF.exe;L:\Share\MurphyMin\CreoBox\");
                    System.Diagnostics.Process.Start("explorer.exe", this.TargetPath);
                }
                else
                {
                    if (string.IsNullOrEmpty(txt_Width1.Text))
                    {
                        XtraMessageBox.Show("阔度1不能为空!");
                        return;
                    }
                    if (string.IsNullOrEmpty(txt_Width2.Text))
                    {
                        XtraMessageBox.Show("阔度2不能为空!");
                        return;
                    }
                    if (string.IsNullOrEmpty(cboxPart_Thick.Text))
                    {
                        XtraMessageBox.Show("板材厚度不能为空!");
                        return;
                    }
                    //if (string.IsNullOrEmpty(cmbWidth1.Text))
                    //{
                    //    XtraMessageBox.Show("阔度1选值不能为空!");
                    //    return;
                    //}
                    //if (string.IsNullOrEmpty(cmbWidth2.Text))
                    //{
                    //    XtraMessageBox.Show("阔度2选值不能为空!");
                    //    return;
                    //}

                    //导出CSV文件
                    string strSql = @"SELECT a.NC_TYPE AS 转码类别,a.JOB_NO AS 工作单号,a.MODEL_NO AS 产品型号,
                a.PART_NO AS 部件编号,a.DWG_NO AS 图纸编号,a.PART_DESC AS 部件描述,a.GRAIN AS 木纹方向,
				a.THICK AS 部件厚度,a.CREATED_USER AS 号码创建,
                a.IMPORT_TIME AS 导入时间,b.PLANNING_ENGINEER AS 计划转码,b.PLANNING_DONETIME AS 计划完成,
                b.CONVERTED_TIME AS 转码完成,b.CHECHED_TIME AS 审核完成,b.RELEASED_TIME AS 上载完成,
                b.LOCKED_USER AS 锁定用户,b.ISSUE_NO AS 问题单号,a.MODEL_NO as 模型编号
                FROM NC_Convert_TaskList AS a
                INNER JOIN NC_Convert_ProcessRecord AS b
                ON a.PART_NO=b.PART_NO AND b.RELEASED_TIME IS NULL where PLANNING_ENGINEER!='admin'";
                    strSql += " and a.PART_NO='" + PartNo + "'";
                    DataTable dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(strSql);
                    NC_Convert_TaskListInfo model = BaseFactory<NC_Convert_TaskList>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();

                    string UpValue = "";
                    string DownValue = "";
                    string LeftValue = "";
                    string RightValue = "";
                    double iValue = (int)double.Parse(dt.Rows[0]["部件厚度"].ToString());
                    string strValue = "";
                    if (double.Parse(dt.Rows[0]["部件厚度"].ToString()) < 10)
                        strValue = "0" + (int)double.Parse(dt.Rows[0]["部件厚度"].ToString());
                    else
                        strValue = ((int)double.Parse(dt.Rows[0]["部件厚度"].ToString())).ToString();
                    //int result = Convert.ToInt32(cmb_UpValue.Text);
                    if (cmb_UpValue.Text.ToLower().Contains("s"))
                    {

                        if (cmb_UpValue.Text.Contains("2"))
                            UpValue = "S" + strValue + cmb_UpValue.Text.Replace("S", "").Replace(".", "").Trim() + "0";
                        else
                            UpValue = "S" + strValue + cmb_UpValue.Text.Replace("S", "").Replace(".", "").Trim();
                        if (!isNumberic(cmb_Up.Text))
                        {
                            string[] arr = cmb_Up.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                UpValue += "XX";
                            else
                                UpValue += arr[1].Trim();
                        }

                    }
                    else if (cmb_UpValue.Text == "0")
                    {
                        UpValue = strValue;
                        if (!isNumberic(cmb_Up.Text))
                        {
                            string[] arr = cmb_Up.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                UpValue += "XX";
                            else
                                UpValue += arr[1].Trim();
                        }
                    }
                    else
                    {
                        if (cmb_UpValue.Text.Contains("2"))
                            UpValue = strValue + cmb_UpValue.Text.Replace(".", "").Trim() + "0";
                        else
                            UpValue = strValue + cmb_UpValue.Text.Replace(".", "").Trim();
                        if (!isNumberic(cmb_Up.Text))
                        {
                            string[] arr = cmb_Up.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                UpValue += "XX";
                            else
                                UpValue += arr[1].Trim();
                        }
                    }


                    if (cmb_DownValue.Text.ToLower().Contains("s"))
                    {
                        if (cmb_DownValue.Text.Contains("2"))
                            DownValue = "S" + strValue + cmb_DownValue.Text.Replace("S", "").Replace(".", "").Trim() + "0";
                        else
                            DownValue = "S" + strValue + cmb_DownValue.Text.Replace("S", "").Replace(".", "").Trim();
                        if (!isNumberic(cmb_Up.Text))
                        {
                            string[] arr = cmb_Up.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                DownValue += "XX";
                            else
                                DownValue += arr[1].Trim();

                        }

                    }
                    else if (cmb_DownValue.Text == "0")
                    {
                        DownValue = strValue;
                        if (!isNumberic(cmb_Down.Text))
                        {
                            string[] arr = cmb_Down.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                DownValue += "XX";
                            else
                                DownValue += arr[1].Trim();
                        }
                    }
                    else
                    {
                        if (cmb_DownValue.Text.Contains("2"))
                            DownValue = strValue + cmb_DownValue.Text.Replace(".", "").Trim() + "0";
                        else
                            DownValue = strValue + cmb_DownValue.Text.Replace(".", "").Trim();
                        if (!isNumberic(cmb_Down.Text))
                        {
                            string[] arr = cmb_Down.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                DownValue += "XX";
                            else
                                DownValue += arr[1].Trim();
                        }
                    }

                    if (cmb_LeftValue.Text.ToLower().Contains("s"))
                    {
                        if (cmb_LeftValue.Text.Contains("2"))
                            LeftValue = "S" + strValue + cmb_LeftValue.Text.Replace("S", "").Replace(".", "").Trim() + "0";
                        else
                            LeftValue = "S" + strValue + cmb_LeftValue.Text.Replace("S", "").Replace(".", "").Trim();
                        if (!isNumberic(cmb_Left.Text))
                        {
                            string[] arr = cmb_Left.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                LeftValue += "XX";
                            else
                                LeftValue += arr[1].Trim();

                        }

                    }
                    else if (cmb_LeftValue.Text == "0")
                    {
                        LeftValue = strValue;
                        if (!isNumberic(cmb_Left.Text))
                        {
                            string[] arr = cmb_Left.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                LeftValue += "XX";
                            else
                                LeftValue += arr[1].Trim();
                        }
                    }
                    else
                    {
                        if (cmb_LeftValue.Text.Contains("2"))
                            LeftValue = strValue + cmb_LeftValue.Text.Replace(".", "") + "0";
                        else
                            LeftValue = strValue + cmb_LeftValue.Text.Replace(".", "");

                        if (!isNumberic(cmb_Left.Text))
                        {
                            string[] arr = cmb_Left.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                LeftValue += "XX";
                            else
                                LeftValue += arr[1].Trim();
                        }
                    }


                    if (cmb_RightValue.Text.ToLower().Contains("s"))
                    {

                        RightValue = "S" + strValue + cmb_RightValue.Text.Replace("S", "").Replace(".", "") + "0";
                        if (!isNumberic(cmb_Right.Text))
                        {
                            string[] arr = cmb_Right.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                RightValue += "XX";
                            else
                                RightValue += arr[1].Trim();
                        }

                    }
                    else if (cmb_Right.Text == "0")
                    {
                        RightValue = strValue;
                        if (!isNumberic(cmb_Right.Text))
                        {
                            string[] arr = cmb_Right.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                RightValue += "XX";
                            else
                                RightValue += arr[1].Trim();
                        }
                    }
                    else
                    {
                        if (cmb_RightValue.Text.Contains("2"))
                            RightValue = strValue + cmb_RightValue.Text.Replace(".", "").Trim() + "0";
                        else
                            RightValue = strValue + cmb_RightValue.Text.Replace(".", "").Trim();
                        if (!isNumberic(cmb_Right.Text))
                        {
                            string[] arr = cmb_Right.Text.Split('_');
                            if (arr[1].Trim().ToLower().Contains("xxx") || arr[1].Trim().ToLower().Contains("nil"))
                                RightValue += "XX";
                            else
                                RightValue += arr[1].Trim();
                        }
                    }

                    FileInfo fi = new FileInfo(tipPath);
                    string path = fi.DirectoryName;
                    string name = fi.Name;
                    path = path + @"\" + pathFileName + ".csv";
                    if (File.Exists(path))
                        File.Delete(path);
                    //File.Create(path);
                    fs = new FileStream(path, FileMode.OpenOrCreate);
                    sw = new StreamWriter(new BufferedStream(fs), System.Text.Encoding.Default);




                    string colHeader = "";

                    colHeader += "文件路径" + ",";
                    colHeader += "标识" + ",";
                    colHeader += "文件编号" + ",";
                    colHeader += "制图" + ",";
                    colHeader += "审核" + ",";
                    colHeader += "生效日期" + ",";
                    colHeader += "产品类别" + ",";
                    colHeader += "型号" + ",";
                    colHeader += "图号" + ",";
                    colHeader += "部件编号" + ",";
                    colHeader += "描述" + ",";
                    colHeader += "表面处理" + ",";
                    colHeader += "材料说明" + ",";
                    colHeader += "木纹方向" + ",";
                    colHeader += "厚度" + ",";
                    colHeader += "阔度_1" + ",";
                    colHeader += "深度_1" + ",";
                    colHeader += "阔度_2" + ",";
                    colHeader += "深度_2" + ",";
                    colHeader += "单开_W" + ",";
                    colHeader += "单开_D" + ",";
                    colHeader += "单开尺寸" + ",";
                    colHeader += "双开_W" + ",";
                    colHeader += "双开_D" + ",";
                    colHeader += "双开尺寸" + ",";
                    colHeader += "封边_C1" + ",";
                    colHeader += "封边_C2" + ",";
                    colHeader += "封边_C3" + ",";
                    colHeader += "封边_C4" + ",";
                    colHeader += "封边_T1" + ",";
                    colHeader += "封边_T2" + ",";
                    colHeader += "封边_T3" + ",";
                    colHeader += "封边_T4" + ",";
                    colHeader += "封边_S1" + ",";
                    colHeader += "封边_S2" + ",";
                    colHeader += "封边_S3" + ",";
                    colHeader += "封边_S4" + ",";
                    colHeader += "工序_01" + ",";
                    colHeader += "工序_02" + ",";
                    colHeader += "工序_03" + ",";
                    colHeader += "工序_04" + ",";
                    colHeader += "工序_05" + ",";
                    colHeader += "工序_06" + ",";
                    colHeader += "工序_07" + ",";
                    colHeader += "工序_08" + ",";
                    colHeader += "工序_09" + ",";
                    colHeader += "工序_10" + ",";
                    colHeader += "底槽1_CD" + ",";
                    colHeader += "底槽2_CD" + ",";
                    colHeader += "底槽3_CD" + ",";
                    colHeader += "底槽4_CD" + ",";
                    colHeader += "侧槽1_CD" + ",";
                    colHeader += "侧槽2_CD" + ",";
                    colHeader += "侧槽3_CD" + ",";
                    colHeader += "侧槽4_CD" + ",";
                    colHeader += "检查标识" + ",";
                    colHeader += "ECN生效" + ",";
                    colHeader += "旋转标识" + ",";
                    colHeader += "C_阔度_1" + ",";
                    colHeader += "C_阔度_2" + ",";
                    colHeader += "C_封边_S1" + ",";
                    colHeader += "C_封边_S2" + ",";
                    colHeader += "C_封边_S3" + ",";
                    colHeader += "C_封边_S4" + ",";
                    colHeader += "C_底槽1_CD" + ",";
                    colHeader += "C_底槽2_CD" + ",";
                    colHeader += "C_底槽3_CD" + ",";
                    colHeader += "C_底槽4_CD" + ",";
                    colHeader += "C_侧槽1_CD" + ",";
                    colHeader += "C_侧槽2_CD" + ",";
                    colHeader += "C_侧槽3_CD" + ",";
                    colHeader += "C_侧槽4_CD" + ",";
                    colHeader += "C_封边_T1" + ",";
                    colHeader += "C_封边_T2" + ",";
                    colHeader += "C_封边_T3" + ",";
                    colHeader += "C_封边_T4" + ",";
                    colHeader = colHeader.Substring(0, colHeader.Length - 1) + "\n";
                    sw.Write(colHeader);
                    string line = "";
                    //line += row[i].ToString().Replace(",", "") + ",";
                    line += path + ",";//文件路径
                    line += PartNo + ",";//标识
                    line += dt.Rows[0]["工作单号"].ToString() + ",";//文件编号
                    line += Loginer.CurrentUser.AccountName + ",";//制图
                    line += Loginer.CurrentUser.AccountName + ",";//审核
                    line += DateTime.Now.ToString() + ",";//生效日期
                    line += dt.Rows[0]["产品型号"].ToString() + ",";//产品类别 
                    line += dt.Rows[0]["产品型号"].ToString() + ",";//型号
                    line += dt.Rows[0]["图纸编号"].ToString() + ",";//图号
                    line += dt.Rows[0]["部件编号"].ToString() + ",";//部件编号
                    line += dt.Rows[0]["部件描述"].ToString().Replace(",", "-") + ",";//描述
                    line += "MFC" + ",";//表面处理
                    line += dt.Rows[0]["部件厚度"].ToString() + "mm MFC" + ",";//材料说明部件厚度
                    line += cboxGrain_Direct.Text + ",";//木纹方向
                    line += dt.Rows[0]["部件厚度"].ToString() + ",";//厚度
                    line += (decimal.Parse(txt_Width1.Text) + decimal.Parse(cmbWidth1.Text)).ToString() + ",";//阔度_1 可能会转向。故不采用数据库数据
                    line += "0" + ",";//深度_1
                    line += (decimal.Parse(txt_Width2.Text) + decimal.Parse(cmbWidth2.Text)).ToString() + ",";//阔度_2
                    line += "0" + ",";//深度_2

                    //line += (decimal.Parse(txt_Width1.Text) + decimal.Parse(cmbWidth1.Text)).ToString() + ",";//单开_W
                    //line += (decimal.Parse(txt_Width2.Text) + decimal.Parse(cmbWidth2.Text)).ToString() + ",";//单开_D
                    //need to calculation siglecutting size
                    string rs = "";
                    //decimal iHeight = decimal.Parse(txt_Width1.Text) + decimal.Parse(cmbWidth1.Text);
                    //decimal iWitdh = decimal.Parse(txt_Width2.Text) + decimal.Parse(cmbWidth2.Text);

                    decimal iHeight = decimal.Parse(txt_Width1.Text);
                    decimal iWitdh = decimal.Parse(txt_Width2.Text);

                    double fristValue = 0;
                    double fristSecond = 0;
                    if (rountingType.Contains("D07"))
                    {
                        fristValue = 0;
                        fristSecond = 0;
                        fristValue = double.Parse(iHeight.ToString()) + 4;
                        fristSecond = double.Parse(iWitdh.ToString()) + 4;
                        //fristValue = double.Parse(iHeight.ToString());

                        //fristSecond = double.Parse(iWitdh.ToString());

                        fristValue = fristValue - ReValue(double.Parse(cmb_LeftValue.Text.ToLower().Replace("s", "").Trim()), double.Parse(cmb_RightValue.Text.ToLower().Replace("s", "").Trim()));
                        fristSecond = fristSecond - ReValue(double.Parse(cmb_UpValue.Text.ToLower().Replace("s", "").Trim()), double.Parse(cmb_DownValue.Text.ToLower().Replace("s", "").Trim()));

                        //fristValue = fristValue + (double)model.CUTTED_WIDTH;
                        //fristSecond = fristSecond + (double)model.CUTTED_DEPTH; ;
                        //rs = fristValue + "x" + fristSecond + "x" + cboxPart_Thick.Text;
                        if (cboxGrain_Direct.Text == "H_横纹")
                            rs = "[" + fristValue + "]" + "x" + fristSecond + "x" + cboxPart_Thick.Text;
                        else if (cboxGrain_Direct.Text == "V_直纹")
                            rs = fristValue + "x" + "[" + fristSecond + "]" + "x" + cboxPart_Thick.Text;
                        else
                            rs = fristValue + "x" + fristSecond + "x" + cboxPart_Thick.Text;
                    }
                    else if (rountingType.Contains("D14_D21"))
                    {
                        fristValue = double.Parse(iHeight.ToString());
                        fristSecond = double.Parse(iWitdh.ToString());

                        //rs = fristValue + "x" + fristSecond;
                        if (cboxGrain_Direct.Text == "H_横纹")
                            rs = "[" + fristValue + "]" + "x" + fristSecond ;
                        else if (cboxGrain_Direct.Text == "V_直纹")
                            rs = fristValue + "x" + "[" + fristSecond + "]" ;
                        else
                            rs = fristValue + "x" + fristSecond + "x" ;
                    }
                    else if (rountingType.Contains("D14_D32"))
                    {

                        fristValue = double.Parse(iHeight.ToString());
                        fristSecond = double.Parse(iWitdh.ToString());

                        //rs = fristValue + "x" + fristSecond;
                        if (cboxGrain_Direct.Text == "H_横纹")
                            rs = "[" + fristValue + "]" + "x" + fristSecond;
                        else if (cboxGrain_Direct.Text == "V_直纹")
                            rs = fristValue + "x" + "[" + fristSecond + "]";
                        else
                            rs = fristValue + "x" + fristSecond + "x";
                    }
                    else if (rountingType.Contains("D14_D28"))
                    {
                        fristValue = 0;
                        fristSecond = 0;
                        fristValue = double.Parse(iHeight.ToString()) + 2;
                        fristSecond = double.Parse(iWitdh.ToString()) + 2;
                        //fristValue = double.Parse(iHeight.ToString()) ;
                        //fristSecond = double.Parse(iWitdh.ToString()) ;

                        fristValue = fristValue - ReValue(double.Parse(cmb_LeftValue.Text.ToLower().Replace("s", "").Trim()), double.Parse(cmb_RightValue.Text.ToLower().Replace("s", "").Trim()));
                        fristSecond = fristSecond - ReValue(double.Parse(cmb_UpValue.Text.ToLower().Replace("s", "").Trim()), double.Parse(cmb_DownValue.Text.ToLower().Replace("s", "").Trim()));
                        //fristValue = fristValue + (double)model.CUTTED_WIDTH;
                        //fristSecond = fristSecond + (double)model.CUTTED_DEPTH;
                        //rs = fristValue + "x" + fristSecond + "x" + cboxPart_Thick.Text;
                        if (cboxGrain_Direct.Text == "H_横纹")
                            rs = "[" + fristValue + "]" + "x" + fristSecond + "x" + cboxPart_Thick.Text;
                        else if (cboxGrain_Direct.Text == "V_直纹")
                            rs = fristValue + "x" + "[" + fristSecond + "]" + "x" + cboxPart_Thick.Text;
                        else
                            rs = fristValue + "x" + fristSecond + "x" + cboxPart_Thick.Text;
                    }
                    else
                    {
                        fristValue = 0;
                        fristSecond = 0;
                        if (string.IsNullOrEmpty(iHeight.ToString()))
                            fristValue = 0;
                        else
                            fristValue = double.Parse(iHeight.ToString());

                        if (string.IsNullOrEmpty(iWitdh.ToString()))
                            fristSecond = 0;
                        else
                            fristSecond = double.Parse(iWitdh.ToString());

                        fristValue = fristValue - ReValue(double.Parse(cmb_LeftValue.Text.ToLower().Replace("s", "").Trim()), double.Parse(cmb_RightValue.Text.ToLower().Replace("s", "").Trim()));
                        fristSecond = fristSecond - ReValue(double.Parse(cmb_UpValue.Text.ToLower().Replace("s", "").Trim()), double.Parse(cmb_DownValue.Text.ToLower().Replace("s", "").Trim()));
                        //fristValue = fristValue + (double)model.CUTTED_WIDTH;
                        //fristSecond = fristSecond + (double)model.CUTTED_DEPTH;
                        if(cboxGrain_Direct.Text== "H_横纹")
                            rs = "["+fristValue+"]" + "x" + fristSecond + "x" + cboxPart_Thick.Text;
                        else if (cboxGrain_Direct.Text == "V_直纹")
                            rs = fristValue + "x" +"["+ fristSecond + "]" + "x" + cboxPart_Thick.Text;
                        else
                            rs = fristValue + "x" + fristSecond + "x" + cboxPart_Thick.Text;
                    }

                    line += fristValue.ToString() + ",";//单开_W
                    line += fristSecond.ToString() + ",";//单开_D

                    line += rs + ",";//单开尺寸
                    line += "0" + ",";//双开_W
                    line += "0" + ",";//双开_D
                    line += "NULL" + ",";//双开尺寸s
                    line += cmb_Up.Text + ",";//封边_C1
                    line += cmb_Down.Text + ",";//封边_C2
                    line += cmb_Left.Text + ",";//封边_C3
                    line += cmb_Right.Text + ",";//封边_C4
                    line += cmb_UpValue.Text.Replace("S","").Trim() + ",";//封边_T1
                    line += cmb_DownValue.Text.Replace("S", "").Trim() + ",";//封边_T2
                    line += cmb_LeftValue.Text.Replace("S", "").Trim() + ",";//封边_T3
                    line += cmb_RightValue.Text.Replace("S", "").Trim() + ",";//封边_T4
                    if (cmb_Up.Text.Substring(0, 3) == "196")
                        line += cmb_Up.Text.Trim() + ",";//封边_S1
                    else
                        line += UpValue.Trim() + ",";//封边_S1
                    if (cmb_Down.Text.Substring(0, 3) == "196")
                        line += cmb_Down.Text.Trim() + ",";//封边_S2
                    else
                        line += DownValue.Trim() + ",";//封边_S2
                    if (cmb_Left.Text.Substring(0, 3) == "196")
                        line += cmb_Left.Text.Trim() + ",";//封边_S3
                    else
                        line += LeftValue.Trim() + ",";//封边_S3
                    if (cmb_Right.Text.Substring(0, 3) == "196")
                        line += cmb_Right.Text.Trim() + ",";//封边_S4
                    else
                        line += RightValue.Trim() + ",";//封边_S4
                    line += "X" + ",";//工序_01
                    line += "X" + ",";//工序_02
                    line += "X" + ",";//工序_03
                    line += "X" + ",";//工序_04
                    line += "X" + ",";//工序_05
                    line += "X" + ",";//工序_06
                    line += "X" + ",";//工序_07
                    line += "X" + ",";//工序_08
                    line += "X" + ",";//工序_09
                    line += "X" + ",";//工序_10
                    line += "XXXX" + ",";//底槽1_CD
                    line += "XXXX" + ",";//底槽2_CD
                    line += "XXXX" + ",";//底槽3_CD
                    line += "XXXX" + ",";//底槽4_CD
                    line += "XXXX" + ",";//侧槽1_CD
                    line += "XXXX" + ",";//侧槽2_CD
                    line += "XXXX" + ",";//侧槽3_CD
                    line += "XXXX" + ",";//侧槽4_CD
                    line += "NULL" + ",";//检查标识
                    line += "NULL" + ",";//ECN生效
                    if (!string.IsNullOrEmpty(rs) && double.Parse(txt_Width1.Text) < double.Parse(txt_Width2.Text))
                        line += "1" + ",";//旋转标识
                    else
                        line += "0" + ",";//旋转标识
                    line += txt_Width1.Text + ",";//C_阔度_1
                    line += txt_Width2.Text + ",";//C_阔度_2
                    if (!string.IsNullOrEmpty(rs) && double.Parse(txt_Width1.Text) < double.Parse(txt_Width2.Text))
                    {
                        if (cmb_Left.Text.Substring(0, 3) == "196")
                            line += cmb_Left.Text.Trim() + ",";//C_封边_S1
                        else
                            line += LeftValue.Trim() + ",";//C_封边_S1
                        if (cmb_Right.Text.Substring(0, 3) == "196")
                            line += cmb_Right.Text.Trim() + ",";//C_封边_S2
                        else
                            line += RightValue.Trim() + ",";//C_封边_S2
                        if (cmb_Down.Text.Substring(0, 3) == "196")
                            line += cmb_Down.Text.Trim() + ",";//C_封边_S3
                        else
                            line += DownValue.Trim() + ",";//C_封边_S3
                        if (cmb_Up.Text.Substring(0, 3) == "196")
                            line += cmb_Up.Text.Trim() + ",";//C_封边_S4
                        else
                            line += UpValue.Trim() + ",";//C_封边_S4
                    }
                    else
                    {
                        if (cmb_Up.Text.Substring(0, 3) == "196")
                            line += cmb_Up.Text.Trim() + ",";//C_封边_S1
                        else
                            line += UpValue.Trim() + ",";//C_封边_S1
                        if (cmb_Down.Text.Substring(0, 3) == "196")
                            line += cmb_Down.Text.Trim() + ",";//C_封边_S2
                        else
                            line += DownValue.Trim() + ",";//C_封边_S2
                        if (cmb_Left.Text.Substring(0, 3) == "196")
                            line += cmb_Left.Text.Trim() + ",";//C_封边_S3
                        else
                            line += LeftValue.Trim() + ",";//C_封边_S3
                        if (cmb_Right.Text.Substring(0, 3) == "196")
                            line += cmb_Right.Text.Trim() + ",";//C_封边_S4
                        else
                            line += RightValue.Trim() + ",";//C_封边_S4
                    }
                    line += "XXXX" + ",";//C_底槽1_CD
                    line += "XXXX" + ",";//C_底槽2_CD
                    line += "XXXX" + ",";//C_底槽3_CD
                    line += "XXXX" + ",";//C_底槽4_CD
                    line += "XXXX" + ",";//C_侧槽1_CD
                    line += "XXXX" + ",";//C_侧槽2_CD
                    line += "XXXX" + ",";//C_侧槽3_CD
                    line += "XXXX" + ",";//C_侧槽4_CD

                    line += cmb_UpValue.Text.Replace("S", "").Trim() + ",";//C_封边_T1
                    line += cmb_DownValue.Text.Replace("S", "").Trim() + ",";//C_封边_T3
                    line += cmb_LeftValue.Text.Replace("S", "").Trim() + ",";//C_封边_T3
                    line += cmb_RightValue.Text.Replace("S", "").Trim() + ",";//C_封边_T4
                    line = line.Substring(0, line.Length - 1) + "\n";
                    sw.Write(line);
                    sw.Close();
                    fs.Close();

                    egdeList.Add(UpValue.Trim());
                    egdeList.Add(DownValue.Trim());
                    egdeList.Add(LeftValue.Trim());
                    egdeList.Add(RightValue.Trim());
                    while (true)
                    {
                        if (File.Exists(path))
                        {

                            break;
                        }
                        else
                        {

                            continue;
                        }
                    }
                    XtraMessageBox.Show("成功导出CSV");
                }
                
            }
            catch(Exception ex)
            {
                sw.Close();
                fs.Close();
                XtraMessageBox.Show(ex.Message);
            }


        }

        private void btnAutoCheck_Click(object sender, EventArgs e)
        {
            Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\NCSJReviewer.exe;L:\Share\MurphyMin\CreoBox\");
        }

        private void cmbWidth1_TextChanged(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(cmbWidth1.Text)) cmbWidth1.Text = "0";
            //if (cmbWidth1.Text == "0") return;
            //if (cmbWidth1.Text == "2")
            //{
            //    txt_Width1.Text = (widthNm1 + 2).ToString();
            //}
            //else if (cmbWidth1.Text == "4")
            //{
            //    txt_Width1.Text = (widthNm1 + 4).ToString();
            //}
        }

        private void cmbWidth2_TextChanged(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(cmbWidth2.Text)) cmbWidth1.Text = "0";
            //if (cmbWidth2.Text == "0") return;
            //if (cmbWidth2.Text == "2")
            //{
            //    txt_Width2.Text = (widthNm2 + 2).ToString();
            //}
            //else if (cmbWidth2.Text == "4")
            //{
            //    txt_Width2.Text = (widthNm2 + 4).ToString();
            //}
        }

        private void cmbThickness_TextChanged(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(cmbThickness.Text)) cmbWidth1.Text = "0";
            //if (cmbThickness.Text == "0") return;
            //if (cmbThickness.Text == "2")
            //{
            //    cboxPart_Thick.Text = (widthNm2 + 2).ToString();
            //}
            //else if (cmbWidth2.Text == "4")
            //{
            //    cboxPart_Thick.Text = (widthNm2 + 4).ToString();
            //}
        }

        private void btnIssue_Click(object sender, EventArgs e)
        {
            try
            {
                //Loginer.CurrentUser.FunctionId = "menuNC_Issue_Record";
                Loginer.CurrentUser.FunctionId= "3C608D22-F518-447A-A54E-DF9C40058F2A";
                string dkProcessName = typeof(frmNC_Issue_Register).ToString();
                Form childProcess = MdiTools.ActiveChildWebBrowse((this.MdiParent as IMdiForm) as Form, dkProcessName);
                if (childProcess == null)
                    MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmNC_Issue_Register(PartNo), sender as ToolStripMenuItem);
                else
                {
                    if (childProcess != null)
                    {
                        frmNC_Issue_Register frm = childProcess as frmNC_Issue_Register;
                        frm.initPartNo(PartNo);
                        frm.Show();
                    }
                }
            }
            catch(Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }

        }

        private void btnCheckComform_Click(object sender, EventArgs e)
        {
            try
            {
                string Nc612 = "";
                string Nc3013 = "";
                string NcFMC = "";
                string NcFML = "";
                string NcDBLFMC = "";

                DataTable dtTask = BaseBuildSql.GetDataTableBySql(" select *from NC_Convert_TaskList where PART_NO='" + PartNo + "'");
                XmlDocument doc = new XmlDocument();
                doc.Load(Application.StartupPath + "\\PicturePathConfig.xml");
                XmlNode xn = doc.SelectSingleNode("Pictures");
                XmlNodeList xnl = xn.ChildNodes;
                foreach (XmlNode xn1 in xnl)
                {
                    XmlElement xe = (XmlElement)xn1;
                    XmlNodeList xn2 = xe.ChildNodes;
                    foreach (XmlElement x2 in xn2)
                    {
                        if (x2.Name == "NC_DK_SJ02")
                            nC_DK_SJ02 = x2.InnerText;
                        if (x2.Name == "NC_DK_SJ01")
                            nC_DK_SJ01 = x2.InnerText;
                        if (x2.Name == "NcfmlPath")
                            NcFML = x2.InnerText;
                        if (x2.Name == "NcfmcPath")
                            NcFMC = x2.InnerText;
                        if (x2.Name == "Ncdxf612Path")
                            Nc612 = x2.InnerText;
                        if (x2.Name == "NccNc3013Path")
                            Nc3013 = x2.InnerText;
                    }
                }

                NC_Convert_ProcessRecordInfo bll = BaseFactory<NC_Convert_ProcessRecord>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
                if (bll != null)
                {
                    if (bll.NC_STATE.Trim() == "待修改")
                    {
                        XtraMessageBox.Show("此单有修改，待重新转码后再审核！");
                        return;
                    }

                    if (bll.NC_STATE.Trim() == "已审核")
                    {
                        XtraMessageBox.Show("已确认，请勿重复确认！");
                        return;
                    }
                    if (bll.NC_STATE.Trim() == "改图纸")
                    {
                        XtraMessageBox.Show("此单有修改，待重新转码后再审核！");
                        return;
                    }

                    string ncUpLoad = nC_DK_SJ02 + @"\" + PartNo; ;
                    string movePath = nC_DK_SJ01 + @"\" + PartNo;

                    string _ncUpLoadFML = movePath + @"\" + PartNo + "_SNG.FML";
                    string _ncUpLoadFMC = movePath + @"\" + PartNo + "_SNG.FMC";
                    string _ncUpLoadDBLFMC = movePath + @"\" + PartNo + "_DBL.FMC";
                    string _ncUpLoad612 = movePath + @"\" + PartNo + "_SNG.DXF";
                    string _ncUpLoad3013 = movePath + @"\" + PartNo + "_SNG.DXF";
                    if (machineType.ToLower() == "puh")
                    {
                        if(!File.Exists(_ncUpLoadFML))
                        {
                            XtraMessageBox.Show("文件不存在："+ _ncUpLoadFML);
                            return;
                        }
                        //if (!File.Exists("文件不存在："+_ncUpLoadDBLFMC))
                        //{
                        //    XtraMessageBox.Show("文件不存在：" + _ncUpLoadDBLFMC);
                        //    return;
                        //}
                        //if (!File.Exists(_ncUpLoad612))
                        //{
                        //    XtraMessageBox.Show("文件不存在：" + _ncUpLoad612);
                        //    return;
                        //}
                        
                    }
                    else if (machineType.ToLower() == "bima")
                    {
                        if (dtTask.Rows[0]["DOUBLE_CUT_SIZE"].ToString() == "NULL" || dtTask.Rows[0]["DOUBLE_CUT_SIZE"].ToString().Trim() == "")
                        {
                            if (!File.Exists(_ncUpLoadFMC))
                            {
                                XtraMessageBox.Show("文件不存在：" + _ncUpLoadFMC);
                                return;
                            }
                        }
                        else
                        {
                            if (!File.Exists(_ncUpLoadFMC))
                            {
                                XtraMessageBox.Show("文件不存在：" + _ncUpLoadFMC);
                                return;
                            }
                            if (!File.Exists(_ncUpLoadDBLFMC))
                            {
                                XtraMessageBox.Show("文件不存在：" + _ncUpLoadDBLFMC);
                                return;
                            }
                        }

                        //if (!File.Exists(_ncUpLoad612))
                        //{
                        //    XtraMessageBox.Show("文件不存在：" + _ncUpLoad612);
                        //    return;
                        //}
                    }
                    else if (machineType.ToLower() == "无")
                    {

                    }
                    else
                    {
                        
                            //if (!File.Exists(_ncUpLoadFML))
                            //{
                            //    XtraMessageBox.Show("文件不存在：" + _ncUpLoadFML);
                            //    return;
                            //}
                            //if (!File.Exists(_ncUpLoadFMC))
                            //{
                            //    XtraMessageBox.Show("文件不存在：" + _ncUpLoadFMC);
                            //    return;
                            //}
                            //if (!File.Exists("文件不存在：" + _ncUpLoadDBLFMC))
                            //{
                            //    XtraMessageBox.Show("文件不存在：" + _ncUpLoadDBLFMC);
                            //    return;
                            //}
                         if (!File.Exists(_ncUpLoad612))
                        {
                            XtraMessageBox.Show("文件不存在：" + _ncUpLoad612);
                            return;
                        }
                        
                    }
                    
                    if (Directory.Exists(nC_DK_SJ02))
                    {

                        NcUploadHelper ncUploadHelper = new NcUploadHelper();
                        if (!ncUploadHelper.IsReturnSJ(movePath + @"\" + PartNo + ".csv"))
                            return;
                        //Thread.Sleep(5*1000);
                        if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                        {

                            MCreoDll.setDir();
                            if (!MCreoDll.flagDir())
                            {
                                XtraMessageBox.Show("Creo 解除占用失败！");
                                return;
                            }
                        }
                        DirectoryInfo di = new DirectoryInfo(movePath);//移动文件
                        di.MoveTo(ncUpLoad);

                        if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                        {
                            string ncUpLoadFML = ncUpLoad + @"\" + PartNo + "_SNG.FML";
                            string ncUpLoadFMC = ncUpLoad + @"\" + PartNo + "_SNG.FMC";
                            string ncUpLoadDBLFMC = ncUpLoad + @"\" + PartNo + "_DBL.FMC";
                            string ncUpLoad612 = ncUpLoad + @"\" + PartNo + "_SNG.DXF";
                            string ncUpLoad3013 = ncUpLoad + @"\" + PartNo + "_SNG.DXF";
                            NcDBLFMC = NcFMC;
                            NcFML = NcFML + @"\" + PartNo + "_SNG.FML";
                            NcFMC = NcFMC + @"\" + PartNo + "_SNG.FMC";
                            NcDBLFMC = NcDBLFMC + @"\" + PartNo + "_DBL.FMC";
                            Nc612 = Nc612 + @"\" + PartNo + "_SNG.DXF";
                            Nc3013 = Nc3013 + @"\" + PartNo + "_SNG.DXF";
                            //string s = "";
                            if (File.Exists(NcFML)) //target file
                                File.Delete(NcFML);
                            if (File.Exists(NcFMC))
                                File.Delete(NcFMC);
                            if (File.Exists(Nc612))
                                File.Delete(Nc612);
                            if (File.Exists(Nc3013))
                                File.Delete(Nc3013);
                            if (File.Exists(NcDBLFMC))
                                File.Delete(NcDBLFMC);

                            if (File.Exists(ncUpLoadFML)) //source file
                                File.Copy(ncUpLoadFML, NcFML);
                            if (File.Exists(ncUpLoadFMC))
                                File.Copy(ncUpLoadFMC, NcFMC);
                            if (File.Exists(ncUpLoadDBLFMC))
                                File.Copy(ncUpLoadDBLFMC, NcDBLFMC);
                            if (machineType.ToLower() == "cnc")//DXF_3013,
                            {
                                if (File.Exists(ncUpLoad3013))
                                    File.Copy(ncUpLoad3013, Nc3013);
                            }
                            else if (machineType.ToLower() == "数控钻")//DXF_612
                            {
                                if (File.Exists(ncUpLoad612))
                                    File.Copy(ncUpLoad612, Nc612);
                            }
                        }
                    }


                    //DirectoryInfo d1 = new DirectoryInfo(ncUpLoad);//移动文件
                    //d1.MoveTo(movePath);
                    bll.NC_STATE = "已审核";
                    bll.LOCKED_USER = null;
                    bll.LOCKED_TIME = null;
                    bll.CHECHED_TIME = DateTime.Now;
                    bll.CHECHED_ENGINEER = Loginer.CurrentUser.AccountName;
                    if (BaseFactory<NC_Convert_ProcessRecord>.Instance.Update(bll))
                    {
                        //需要解除文件权限
                        
                        XtraMessageBox.Show("审核成功！");
                        
                        return;
                    }
                    else
                    {
                        XtraMessageBox.Show("审核失败！");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
        }

        private void btnDrawLevel_Click(object sender, EventArgs e)
        {
            Lamex.Library.CommonClass.MdiTools.OpenIE(@"L:\Share\MurphyMin\CreoBox\NCSJReviewer.exe;L:\Share\MurphyMin\CreoBox\");
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            btnIssue_Click(null, null);
        }

        private void frmNC_Convert_DKSJR_Processing_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                {
                    MCreoDll.closeCreo();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Creo 异常");
            }
        }

        private void cmb_LeftValue_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {
            try
            {
                string Nc612 = "";
                string Nc3013 = "";
                string NcFMC = "";
                string NcFML = "";
                string NcDBLFMC = "";

                DataTable dtTask = BaseBuildSql.GetDataTableBySql(" select *from NC_Convert_TaskList where PART_NO='" + PartNo + "'");
                XmlDocument doc = new XmlDocument();
                doc.Load(Application.StartupPath + "\\PicturePathConfig.xml");
                XmlNode xn = doc.SelectSingleNode("Pictures");
                XmlNodeList xnl = xn.ChildNodes;
                foreach (XmlNode xn1 in xnl)
                {
                    XmlElement xe = (XmlElement)xn1;
                    XmlNodeList xn2 = xe.ChildNodes;
                    foreach (XmlElement x2 in xn2)
                    {
                        if (x2.Name == "NC_DK_SJ02")
                            nC_DK_SJ02 = x2.InnerText;
                        if (x2.Name == "NC_DK_SJ01")
                            nC_DK_SJ01 = x2.InnerText;
                        if (x2.Name == "NcfmlPath")
                            NcFML = x2.InnerText;
                        if (x2.Name == "NcfmcPath")
                            NcFMC = x2.InnerText;
                        if (x2.Name == "Ncdxf612Path")
                            Nc612 = x2.InnerText;
                        if (x2.Name == "NccNc3013Path")
                            Nc3013 = x2.InnerText;
                    }
                }

                NC_Convert_ProcessRecordInfo bll = BaseFactory<NC_Convert_ProcessRecord>.Instance.GetEntriyList(" 1=1 and PART_NO='" + PartNo + "'").FirstOrDefault();
                if (bll != null)
                {
                    
                    string ncUpLoad = nC_DK_SJ02 + @"\" + PartNo; ;
                    string movePath = nC_DK_SJ01 + @"\" + PartNo;

                    string _ncUpLoadFML = movePath + @"\" + PartNo + "_SNG.FML";
                    string _ncUpLoadFMC = movePath + @"\" + PartNo + "_SNG.FMC";
                    string _ncUpLoadDBLFMC = movePath + @"\" + PartNo + "_DBL.FMC";
                    string _ncUpLoad612 = movePath + @"\" + PartNo + "_SNG.DXF";
                    string _ncUpLoad3013 = movePath + @"\" + PartNo + "_SNG.DXF";
                    if (machineType.ToLower() == "puh")
                    {
                        if (!File.Exists(_ncUpLoadFML))
                        {
                            XtraMessageBox.Show("文件不存在：" + _ncUpLoadFML);
                            return;
                        }
                       
                    }
                    else if (machineType.ToLower() == "bima")
                    {
                        if (dtTask.Rows[0]["DOUBLE_CUT_SIZE"].ToString() == "NULL" || dtTask.Rows[0]["DOUBLE_CUT_SIZE"].ToString().Trim() == "")
                        {
                            if (!File.Exists(_ncUpLoadFMC))
                            {
                                XtraMessageBox.Show("文件不存在：" + _ncUpLoadFMC);
                                return;
                            }
                        }
                        else
                        {
                            if (!File.Exists(_ncUpLoadFMC))
                            {
                                XtraMessageBox.Show("文件不存在：" + _ncUpLoadFMC);
                                return;
                            }
                            if (!File.Exists(_ncUpLoadDBLFMC))
                            {
                                XtraMessageBox.Show("文件不存在：" + _ncUpLoadDBLFMC);
                                return;
                            }
                        }

                        
                    }
                    else if (machineType.ToLower() == "无")
                    {

                    }
                    else
                    {

                        
                        if (!File.Exists(_ncUpLoad612))
                        {
                            XtraMessageBox.Show("文件不存在：" + _ncUpLoad612);
                            return;
                        }

                    }

                    if (Directory.Exists(nC_DK_SJ02))
                    {

                        NcUploadHelper ncUploadHelper = new NcUploadHelper();
                        //if (!ncUploadHelper.IsReturnSJ(movePath + @"\" + PartNo + ".csv"))
                        //    return;
                        ////Thread.Sleep(5*1000);
                        //if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                        //{

                        //    MCreoDll.setDir();
                        //    if (!MCreoDll.flagDir())
                        //    {
                        //        XtraMessageBox.Show("Creo 解除占用失败！");
                        //        return;
                        //    }
                        //}
                        DirectoryInfo di = new DirectoryInfo(movePath);//移动文件
                        di.MoveTo(ncUpLoad);

                        if (!(!rountingType.Contains("D11") && !rountingType.Contains("D21") && !rountingType.Contains("D30") && !rountingType.Contains("D32")))
                        {
                            string ncUpLoadFML = ncUpLoad + @"\" + PartNo + "_SNG.FML";
                            string ncUpLoadFMC = ncUpLoad + @"\" + PartNo + "_SNG.FMC";
                            string ncUpLoadDBLFMC = ncUpLoad + @"\" + PartNo + "_DBL.FMC";
                            string ncUpLoad612 = ncUpLoad + @"\" + PartNo + "_SNG.DXF";
                            string ncUpLoad3013 = ncUpLoad + @"\" + PartNo + "_SNG.DXF";
                            NcDBLFMC = NcFMC;
                            NcFML = NcFML + @"\" + PartNo + "_SNG.FML";
                            NcFMC = NcFMC + @"\" + PartNo + "_SNG.FMC";
                            NcDBLFMC = NcDBLFMC + @"\" + PartNo + "_DBL.FMC";
                            Nc612 = Nc612 + @"\" + PartNo + "_SNG.DXF";
                            Nc3013 = Nc3013 + @"\" + PartNo + "_SNG.DXF";
                            //string s = "";
                            if (File.Exists(NcFML)) //target file
                                File.Delete(NcFML);
                            if (File.Exists(NcFMC))
                                File.Delete(NcFMC);
                            if (File.Exists(Nc612))
                                File.Delete(Nc612);
                            if (File.Exists(Nc3013))
                                File.Delete(Nc3013);
                            if (File.Exists(NcDBLFMC))
                                File.Delete(NcDBLFMC);

                            if (File.Exists(ncUpLoadFML)) //source file
                                File.Copy(ncUpLoadFML, NcFML);
                            if (File.Exists(ncUpLoadFMC))
                                File.Copy(ncUpLoadFMC, NcFMC);
                            if (File.Exists(ncUpLoadDBLFMC))
                                File.Copy(ncUpLoadDBLFMC, NcDBLFMC);
                            if (machineType.ToLower() == "cnc")//DXF_3013,
                            {
                                if (File.Exists(ncUpLoad3013))
                                    File.Copy(ncUpLoad3013, Nc3013);
                            }
                            else if (machineType.ToLower() == "数控钻")//DXF_612
                            {
                                if (File.Exists(ncUpLoad612))
                                    File.Copy(ncUpLoad612, Nc612);
                            }
                        }
                    }


                    DirectoryInfo d1 = new DirectoryInfo(ncUpLoad);//移动文件
                    
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
        }
    }


    public class MCreoDll
    {
        [DllImport("MCreoDll.dll", CharSet = CharSet.Ansi)]
        public static extern void setDir();
        [DllImport("MCreoDll.dll", CharSet = CharSet.Ansi)]
        public static extern void erase3d();
        [DllImport("MCreoDll.dll", CharSet = CharSet.Ansi)]
        public static extern bool flagDir();
        [DllImport("MCreoDll.dll", CharSet = CharSet.Ansi)]
        public static extern bool closeCreo();


    }

}